Ejemplo n.º 1
0
 /**
  * Filter the parsed result to the schema.
  *
  * @param  \Detection\MobileDetect $parsed
  * @return array
  */
 public function filter($parsed)
 {
     $filtered = array();
     // Filtering mechanishm for MobileDetect 2.* versions.
     $filter = function ($items) use($parsed) {
         // Play down the $parsed->is('Android'); mechanishm.
         foreach ($items as $key => $regex) {
             if ($parsed->is($key)) {
                 return $key;
             }
         }
         return null;
     };
     // Operating system's family.
     $filtered['osFamily'] = $filter($parsed->getOperatingSystems());
     // Browser's family.
     $filtered['browserFamily'] = $filter($parsed->getBrowsers());
     // Just 'mobile' kind devices.
     if ($parsed->isMobile() and !$parsed->isTablet()) {
         $filtered['isMobile'] = true;
         $filtered['mobileGrade'] = $parsed->mobileGrade();
         $filtered['deviceModel'] = $filter($parsed->getPhoneDevices());
     } elseif ($parsed->isTablet()) {
         $filtered['isTablet'] = true;
         $filtered['mobileGrade'] = $parsed->mobileGrade();
         $filtered['deviceModel'] = $filter($parsed->getTabletDevices());
     }
     // Clear the generic and null values.
     $filtered = array_filter(array_filter($filtered, function ($value) {
         return !preg_match('%^generic%i', $value);
     }));
     return $filtered;
 }
Ejemplo n.º 2
0
 /**
  * @Flow\Around("method(TYPO3\Flow\Mvc\ActionRequest->isTablet())")
  * @param JoinPointInterface $joinPoint
  * @return boolean
  */
 public function isTablet(JoinPointInterface $joinPoint)
 {
     if ($this->mobileDetection === NULL) {
         $this->initializeMobileDetection();
     }
     return $this->mobileDetection->isTablet();
 }
Ejemplo n.º 3
0
 /**
  * @return bool
  */
 public function isMobile()
 {
     if (class_exists(MobileDetect::class)) {
         $detect = new MobileDetect();
         return $detect->isMobile() || $detect->isTablet();
     }
     return true;
 }
 /**
  * SetUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Request::addDetector('mobile', function ($request) {
         $detector = new MobileDetect();
         return $detector->isMobile();
     });
     Request::addDetector('tablet', function ($request) {
         $detector = new MobileDetect();
         return $detector->isTablet();
     });
     $this->event = new Event('Controller.beforeFilter');
     $this->Controller = new MobileComponentTestController(new Request());
     $this->Controller->request->session()->delete('User');
     Configure::delete('User');
 }