skipBotDetection() публичный Метод

It is needed if we want bots to be processed as a simple clients. So we can detect if it is mobile client, or desktop, or enything else. By default all this information is not retrieved for the bots.
public skipBotDetection ( boolean $skip = true )
$skip boolean
 public function __construct(RequestStack $stack, CacheProvider $cache, $deviceDetectorOptions)
 {
     $this->cacheManager = $cache;
     $this->requestStack = $stack;
     $this->setOptions($deviceDetectorOptions);
     if (null !== $this->requestStack && $this->requestStack->getCurrentRequest()) {
         $userAgent = $this->requestStack->getCurrentRequest()->headers->get('User-Agent');
     } else {
         $userAgent = '';
     }
     $this->deviceDetector = new \DeviceDetector\DeviceDetector($userAgent);
     $this->deviceDetector->setCache($this->getCacheManager());
     if (!empty($this->deviceDetectorOptions['discard_bot_information'])) {
         $this->deviceDetector->discardBotInformation();
     }
     if (!empty($this->deviceDetectorOptions['skip_bot_detection'])) {
         $this->deviceDetector->skipBotDetection();
     }
     $this->deviceDetector->parse();
 }
 public function testSkipBotDetection()
 {
     $ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
     $dd = new DeviceDetector($ua);
     $dd->parse();
     $this->assertFalse($dd->isMobile());
     $this->assertTrue($dd->isBot());
     $dd = new DeviceDetector($ua);
     $dd->skipBotDetection();
     $dd->parse();
     $this->assertTrue($dd->isMobile());
     $this->assertFalse($dd->isBot());
 }
Пример #3
0
 /**
  *
  * @param User $user
  * @return Session|null
  */
 private function findSession(User $user)
 {
     $request = Request::createFromGlobals();
     $ua = $request->headers->get('User-Agent');
     $detector = new DeviceDetector($ua);
     $detector->skipBotDetection(true);
     $detector->parse();
     return SessionQuery::create()->filterByUserId($user->getId())->filterByBrowser($detector->getClient('name'))->filterByOs($detector->getOs('name'))->findOne();
 }