/** * test if is mobile */ public function testIsMobile() { $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); $this->assertFalse($this->ua->isMobile()); $uaStr = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 '; $uaStr .= '(KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'; $this->ua->setUserAgent($uaStr); $this->assertTrue($this->ua->isMobile()); }
/** * 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; }