예제 #1
0
 /**
  * @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);
 }
 /**
  * This method is called before the first test of this test class is run.
  *
  * @since Method available since Release 3.4.0
  */
 public static function setUpBeforeClass()
 {
     $persistenceProvider = new Storage(new Memory());
     $userAgentHandlerChain = UserAgentHandlerChainFactory::createFrom($persistenceProvider, $persistenceProvider);
     $devicePatcher = new DevicePatcher();
     self::$deviceRepositoryBuilder = new DeviceRepositoryBuilder($persistenceProvider, $userAgentHandlerChain, $devicePatcher);
     try {
         self::$deviceRepository = self::$deviceRepositoryBuilder->build(self::RESOURCES_DIR . 'wurfl.xml');
     } catch (Exception $e) {
         echo $e;
     }
 }
 /**
  * This method is called before the first test of this test class is run.
  *
  * @since Method available since Release 3.4.0
  */
 public static function setUpBeforeClass()
 {
     $logger = new NullLogger();
     $persistenceProvider = new Storage(new Memory());
     $userAgentHandlerChain = UserAgentHandlerChainFactory::createFrom($persistenceProvider, $persistenceProvider, $logger);
     $devicePatcher = new DevicePatcher();
     self::$deviceRepositoryBuilder = new DeviceRepositoryBuilder($persistenceProvider, $userAgentHandlerChain, $devicePatcher, $logger);
     try {
         self::$deviceRepository = self::$deviceRepositoryBuilder->build(self::WURFL_FILE);
     } catch (Exception $e) {
         echo $e;
     }
 }
예제 #4
0
 /**
  * Adds the pair $userAgent, $deviceID to the clusters they belong to.
  *
  * @param string $userAgent
  * @param string $deviceID
  *
  * @see \Wurfl\Handlers\AbstractHandler::filter()
  */
 public function filter($userAgent, $deviceID)
 {
     Utils::reset();
     $genericNormalizer = UserAgentHandlerChainFactory::createGenericNormalizers();
     $userAgent = $genericNormalizer->normalize($userAgent);
     $handlers = $this->getHandlers();
     foreach ($handlers as $handler) {
         /** @var $handler \Wurfl\Handlers\AbstractHandler */
         $handler->setLogger($this->logger);
         if ($handler->filter($userAgent, $deviceID)) {
             break;
         }
     }
 }
예제 #5
0
 /**
  * return \Wurfl\Handlers\Chain\UserAgentHandlerChain
  */
 private static function initUserAgentHandlerChain()
 {
     $resourcesDir = self::RESOURCES_DIR;
     $cacheDir = self::CACHE_DIR;
     $config = new InMemoryConfig();
     $config->wurflFile($resourcesDir . 'wurfl.xml');
     $params = array(Config::DIR => $cacheDir, Config::EXPIRATION => 0);
     $config->persistence('file', $params);
     $config->cache('memory');
     $cacheStorage = new Storage(new Memory());
     $persistenceStorage = new Storage(new File($params));
     $logger = new NullLogger();
     $UserAgentHandlerChain = UserAgentHandlerChainFactory::createFrom($persistenceStorage, $cacheStorage, $logger);
     return $UserAgentHandlerChain;
 }
예제 #6
0
파일: Manager.php 프로젝트: mimmi20/wurfl
 /**
  * Wraps the model device with \Wurfl\Xml\ModelDeviceInterface. This function takes the
  * Device ID and returns the \Wurfl\CustomDevice with all capabilities.
  *
  * @param string                 $deviceId
  * @param Request\GenericRequest $request
  *
  * @return \Wurfl\CustomDevice
  */
 private function getWrappedDevice($deviceId, Request\GenericRequest $request = null)
 {
     $modelDevices = $this->getCacheStorage()->load('DEVS_' . $deviceId);
     if (empty($modelDevices)) {
         $modelDevices = $this->getDeviceRepository()->getDeviceHierarchy($deviceId);
     }
     $this->getCacheStorage()->save('DEVS_' . $deviceId, $modelDevices);
     if ($request === null) {
         // If a request was not provided, we generate one from the WURFL entry itself
         // to help resolve the virtual capabilities
         $requestFactory = new GenericRequestFactory();
         $request = $requestFactory->createRequestForUserAgent($modelDevices[0]->userAgent);
         $genericNormalizer = UserAgentHandlerChainFactory::createGenericNormalizers();
         $request->setUserAgentNormalized($genericNormalizer->normalize($request->getUserAgent()));
     }
     // The CustomDevice is not cached since virtual capabilities must be recalculated
     // for every different request.
     return new CustomDevice($modelDevices, $request);
 }