Exemple #1
0
 /**
  * Test Browser Mapping
  */
 public function testBrowserMapping()
 {
     $m1 = new Mapper();
     $m1->setMap('browser', $this->confContainer->getMappings()->getBrowser());
     $m1->setMap('browser_family', $this->confContainer->getMappings()->getBrowserFamily());
     $to = $m1->getToInMap('AB', 'browser');
     $this->assertEquals(76, $to);
     $to = $m1->getTo('AB');
     $this->assertEquals(array(76), $to);
 }
 /**
  * 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;
 }