Example #1
0
 /**
  * Test all Mappings
  */
 public function testAllMappings()
 {
     $m1 = new Mapper();
     $m1->setMap('browser', $this->confContainer->getMappings()->getBrowser());
     $m1->setMap('browser_family', $this->confContainer->getMappings()->getBrowserFamily());
     $m1->setMap('desktop_os', $this->confContainer->getMappings()->getDesktopOs());
     $m1->setMap('device_brand', $this->confContainer->getMappings()->getDeviceBrand());
     $m1->setMap('device_type', $this->confContainer->getMappings()->getDeviceType());
     $m1->setMap('os_family', $this->confContainer->getMappings()->getOsFamily());
     $m1->setMap('os_short', $this->confContainer->getMappings()->getOsShort());
     $this->assertEquals('AB', $m1->getFromInMap(76, 'browser'));
     $this->assertEquals('Android Browser', $m1->getFromInMap(11, 'browser_family'));
     $this->assertEquals('IBM', $m1->getFromInMap(6, 'desktop_os'));
     $this->assertEquals('AC', $m1->getFromInMap(106, 'device_brand'));
     $this->assertEquals('desktop', $m1->getFromInMap(8, 'device_type'));
     $this->assertEquals('Android', $m1->getFromInMap(22, 'os_family'));
     $this->assertEquals('AIX', $m1->getFromInMap(77, 'os_short'));
 }
 /**
  * Returns Os
  *
  * @param bool $throwExceptionIfNotFound
  *
  * @throws InvalidArgumentException
  * @throws ResourceNotFoundException
  * @return OsInterface
  */
 public function getOs($throwExceptionIfNotFound = false)
 {
     if ($this->isInvalidUserAgent($this->parser->getUserAgent())) {
         throw InvalidArgumentException::userAgent($this->parser->getUserAgent());
     }
     if ($this->rebuildOs) {
         try {
             $osStruct = $this->parser->getOs();
             $osName = self::getFromArray($osStruct, 'name');
             $osShortName = self::getFromArray($osStruct, 'short_name');
             $osId = $this->mapper->getToInMap($osName, self::MAP_NAME_OS_SHORT);
         } catch (ResourceNotFoundException $exc) {
             if ($throwExceptionIfNotFound) {
                 throw $exc;
             } else {
                 $osShortName = self::USER_AGENT_UNKNOWN_STR;
                 $osName = self::USER_AGENT_UNKNOWN_STR_LONG;
                 $osId = self::USER_AGENT_UNKNOWN_ID;
             }
         }
         $this->os->setNameShort($osShortName)->setName($osName)->setId($osId);
         try {
             $famShortName = $famName = $this->parser->getOsFamily($osShortName);
             $famId = $this->mapper->getToInMap($famShortName, self::MAP_NAME_OS_FAMILY);
         } catch (ResourceNotFoundException $exc) {
             if ($throwExceptionIfNotFound) {
                 throw $exc;
             } else {
                 $famShortName = self::USER_AGENT_UNKNOWN_STR;
                 $famName = self::USER_AGENT_UNKNOWN_STR_LONG;
                 $famId = self::USER_AGENT_UNKNOWN_ID;
             }
         }
         $oFam = new OsFamily();
         $oFam->setNameShort($famShortName)->setName($famName)->setId($famId);
         $this->os->setFamily($oFam);
         $this->rebuildOs = false;
     }
     return $this->os;
 }