示例#1
0
 /**
  * testGetBrowser
  */
 public function testGetBrowser()
 {
     $uaStr = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ';
     $uaStr .= 'Chrome/29.0.1547.76 Safari/537.36';
     $this->ua->setUserAgent($uaStr);
     $b = $this->ua->getBrowser();
     $this->assertEquals('Chrome', $b['name']);
     $this->assertEquals('CH', $b['short_name']);
 }
示例#2
0
 /**
  * Returns Browser
  *
  * @param bool $throwExceptionIfNotFound
  *
  * @throws InvalidArgumentException
  * @throws ResourceNotFoundException
  *
  * @return BrowserInterface
  *
  */
 public function getBrowser($throwExceptionIfNotFound = false)
 {
     if ($this->isInvalidUserAgent($this->parser->getUserAgent())) {
         throw InvalidArgumentException::userAgent($this->parser->getUserAgent());
     }
     if ($this->rebuildBrowser) {
         try {
             $browserStruct = $this->parser->getBrowser();
             $browserShortName = self::getFromArray($browserStruct, 'short_name');
             $browserName = self::getFromArray($browserStruct, 'name');
             $browserId = $this->mapper->getToInMap($browserShortName, self::MAP_NAME_BROWSER);
         } catch (ResourceNotFoundException $exc) {
             if ($throwExceptionIfNotFound) {
                 throw $exc;
             } else {
                 $browserShortName = self::USER_AGENT_UNKNOWN_STR;
                 $browserName = self::USER_AGENT_UNKNOWN_STR_LONG;
                 $browserId = self::USER_AGENT_UNKNOWN_ID;
             }
         }
         $this->browser->setNameShort($browserShortName)->setName($browserName)->setId($browserId);
         try {
             $famShortName = $famName = $this->parser->getBrowserFamily($browserShortName);
             $famId = $this->mapper->getToInMap($famShortName, self::MAP_NAME_BROWSER_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;
             }
         }
         /* create browser family  */
         $bFam = new BrowserFamily();
         $bFam->setNameShort($famShortName)->setName($famName)->setId($famId);
         $this->browser->setFamily($bFam);
         $this->rebuildBrowser = false;
     }
     return $this->browser;
 }