discardBotInformation(); $dd->skipBotDetection(); if (is_null($userAgent)) { return (Object)[ 'os' => null, 'browser' => null, 'device' => null, 'is_bot' => null, 'is_safari' => null, 'is_chrome' => null, 'is_mobile' => null, 'is_mac' =>null, 'is_windows' =>null, ]; } AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE); $clientHints = ClientHints::factory($_SERVER); $dd = new DeviceDetector($userAgent, $clientHints); $dd->discardBotInformation(); $dd->skipBotDetection(); $redisConnection = RedisAdapter::createConnection('redis:///var/lib/redis/redis.sock/14'); $cache = new RedisAdapter($redisConnection, 43200); // $cache = new ApcuAdapter(); $data = $cache->get(Str::slug($userAgent).'_', function() use ($cache, $dd) { $dd->setCache( new \DeviceDetector\Cache\PSR6Bridge($cache) ); $dd->parse(); $osFamily = OperatingSystem::getOsFamily($dd->getOs('name')); $browserFamily = Browser::getBrowserFamily($dd->getClient('name')); if ($dd->isTablet() || $dd->isPhablet()) { $viewport = 'tablet'; } else if ($dd->isSmartphone() || $dd->isFeaturePhone()) { $viewport = 'phone'; } else { $viewport = 'desktop'; } $data = (Object)[ 'os' => $osFamily, 'browser' => $browserFamily, 'device' => $dd->getDeviceName(), 'is_bot' => $dd->isBot(), 'is_safari' => 'Safari' === $browserFamily, 'is_chrome' => 'Chrome' === $browserFamily, 'is_mobile' => 'phone' === $viewport, 'is_mac' => 'Mac' === $osFamily, 'is_windows' => 'Windows' === $osFamily, ]; if ($data->is_bot) { $data->bot = $dd->getBot()['name'] ?? null; } return $data; }); return $data; } }