/** * tests Clearing the cache */ public function testClear() { $params = array('dir' => 'abc'); $this->root->save('Test', $params); $this->root->clear(); self::assertNull($this->root->load('Test')); }
/** * 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; }
private function verifyRepository() { /** * verify required device ids */ foreach ($this->userAgentHandlerChain->getHandlers() as $handler) { /** * @var \Wurfl\Handlers\AbstractHandler */ foreach ($handler::$constantIDs as $requireDeviceId) { $device = $this->persistenceProvider->load($requireDeviceId); if ($device === null) { throw new ConsistencyException('wurfl.xml load error - device id [' . $requireDeviceId . '] is missing - ' . 'you may need to update the wurfl.xml file to a more recent version'); } } } /** * verify required capabilities */ $requiredCaps = VirtualCapabilityProvider::getRequiredCapabilities(); /** @var \Wurfl\Device\ModelDeviceInterface $genericDevice */ $genericDevice = $this->persistenceProvider->load('generic'); $loadedCaps = array_keys($genericDevice->getCapabilities()); $missingCaps = array_diff($requiredCaps, $loadedCaps); if (count($missingCaps) > 0) { throw new ConsistencyException('Missing required WURFL Capabilities: ' . implode(', ', $missingCaps)); } $invalidFallbacks = array_diff(array_keys($this->fallbacks), $this->devices); if (count($invalidFallbacks) > 0) { foreach ($invalidFallbacks as $invalidFallback) { $device = new CustomDevice(array($this->persistenceProvider->load($this->fallbacks[$invalidFallback]))); throw new ConsistencyException(sprintf('Invalid Fallback %s for the device %s', $invalidFallback, $device->id)); } } $this->fallbacks = array(); $this->devices = array(); }
/** * 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; }