/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage There is no device with ID [generic] in the loaded WURFL Data */ public function testShouldNotRebuildTheRepositoryIfAlreadyBuild() { $logger = new NullLogger(); $persistenceProvider = new Storage(new Memory()); $persistenceProvider->setWURFLLoaded(true); $userAgentHandlerChain = UserAgentHandlerChainFactory::createFrom($persistenceProvider, $persistenceProvider, $logger); $devicePatcher = new DevicePatcher(); $deviceRepositoryBuilder = new DeviceRepositoryBuilder($persistenceProvider, $userAgentHandlerChain, $devicePatcher, $logger); self::assertNotNull($deviceRepositoryBuilder); $deviceRepository = $deviceRepositoryBuilder->build(self::WURFL_FILE); $deviceRepository->getDevice(WurflConstants::GENERIC); }
/** * Returns a list of User Agents associated with the bucket * @return array User agents */ public function getUserAgentsForBucket() { if (empty($this->userAgents)) { $this->userAgents = $this->persistenceProvider->load($this->getPrefix(self::PREFIX_UA_BUCKET)); } return $this->userAgents; }
/** * Returns the value for the given $deviceId and $capabilityName * * @param string $deviceId * @param string $capabilityName * * @throws \InvalidArgumentException device ID or capability was not found * * @return string value */ public function getCapabilityForDevice($deviceId, $capabilityName) { if (!$this->isCapabilityDefined($capabilityName)) { throw new \InvalidArgumentException('capability name: ' . $capabilityName . ' not found'); } $capabilityValue = null; while (strcmp($deviceId, 'root')) { $device = $this->persistenceStorage->load($deviceId); if (!$device) { throw new \InvalidArgumentException('the device with ' . $deviceId . ' is not found.'); } if (isset($device->capabilities[$capabilityName])) { $capabilityValue = $device->capabilities[$capabilityName]; break; } $deviceId = $device->fallBack; } return $capabilityValue; }
/** * Create a \Wurfl\Handlers\Chain\UserAgentHandlerChain * * @param \Wurfl\Storage\Storage $persistenceProvider * @param \Wurfl\Storage\Storage $cacheProvider * @param \Psr\Log\LoggerInterface $logger * * @return UserAgentHandlerChain */ public static function createFrom(Storage $persistenceProvider, Storage $cacheProvider, LoggerInterface $logger = null) { /** @var $userAgentHandlerChain \Wurfl\Handlers\Chain\UserAgentHandlerChain */ $userAgentHandlerChain = $cacheProvider->load('UserAgentHandlerChain'); if (!$userAgentHandlerChain instanceof UserAgentHandlerChain) { $userAgentHandlerChain = self::init(); $cacheProvider->save('UserAgentHandlerChain', $userAgentHandlerChain, 3600); } $userAgentHandlerChain->setLogger($logger); foreach ($userAgentHandlerChain->getHandlers() as $handler) { /* @var $handler \Wurfl\Handlers\AbstractHandler */ $handler->setLogger($logger)->setPersistenceProvider($persistenceProvider); } return $userAgentHandlerChain; }
/** * tests Saving and Loading a record without expiration time */ public function testWurflLoaded() { $this->root->setWURFLLoaded(true); self::assertTrue($this->root->isWURFLLoaded()); }
public static function tearDownAfterClass() { self::$persistenceStorage->clear(); }
/** * Releases the lock if one was acquired */ private function releaseLock() { return $this->persistenceProvider->releaseLock(); }