/** * 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 Device * * @param bool $throwExceptionIfNotFound * * @throws InvalidArgumentException * @throws ResourceNotFoundException * @return DeviceInterface */ public function getDevice($throwExceptionIfNotFound = false) { if ($this->isInvalidUserAgent($this->parser->getUserAgent())) { throw InvalidArgumentException::userAgent($this->parser->getUserAgent()); } if ($this->rebuildDevice) { $dBrand = new DeviceBrand(); $dType = new DeviceType(); if ($this->parser->isMobile()) { $this->device->setNameShort(self::USER_AGENT_UNKNOWN_STR)->setName($this->parser->getDeviceModelName())->setId(self::USER_AGENT_UNKNOWN_ID); try { $deviceBrandShort = $this->parser->getDeviceBrand(); $deviceBrandFull = $this->parser->getDeviceBrandFull(); $deviceBrandId = $this->mapper->getToInMap($deviceBrandShort, self::MAP_NAME_DEVICE_BRAND); } catch (ResourceNotFoundException $exc) { if ($throwExceptionIfNotFound) { throw $exc; } else { $deviceBrandShort = self::USER_AGENT_UNKNOWN_STR; $deviceBrandFull = self::USER_AGENT_UNKNOWN_STR_LONG; $deviceBrandId = self::USER_AGENT_UNKNOWN_ID; } } $dBrand->setNameShort($deviceBrandShort)->setName($deviceBrandFull)->setId($deviceBrandId); } else { /* When this is not a device return NULL/Not Available */ $this->device->setNameShort(self::USER_AGENT_NULL_STR)->setName(self::USER_AGENT_NULL_STR_LONG)->setId(self::USER_AGENT_NULL_ID); $dBrand->setNameShort(self::USER_AGENT_NULL_STR)->setName(self::USER_AGENT_NULL_STR_LONG)->setId(self::USER_AGENT_NULL_ID); } /* DEVICE TYPE */ try { $deviceTypeShort = $this->parser->getDeviceType(); $deviceTypeFull = $this->parser->getDeviceTypeFullName(); $deviceTypedId = $this->mapper->getToInMap($deviceTypeShort, self::MAP_NAME_DEVICE_TYPE); } catch (ResourceNotFoundException $exc) { if ($throwExceptionIfNotFound) { throw $exc; } else { $deviceTypeShort = self::USER_AGENT_UNKNOWN_STR; $deviceTypeFull = self::USER_AGENT_UNKNOWN_STR_LONG; $deviceTypedId = self::USER_AGENT_UNKNOWN_ID; } } $dType->setName($deviceTypeFull)->setNameShort($deviceTypeShort)->setId($deviceTypedId); $this->device->setBrand($dBrand); $this->device->setType($dType); $this->rebuildDevice = false; } return $this->device; }