createCollection() публичный Метод

public createCollection ( Psr\Log\LoggerInterface $logger, string $buildFolder ) : WriterCollection
$logger Psr\Log\LoggerInterface
$buildFolder string
Результат Browscap\Writer\WriterCollection
Пример #1
0
 /**
  * This method is called before the first test of this test class is run.
  */
 public static function setUpBeforeClass()
 {
     // First, generate the INI files
     $buildNumber = time();
     $resourceFolder = __DIR__ . '/../../resources/';
     self::$buildFolder = __DIR__ . '/../../build/browscap-ua-test-' . $buildNumber . '/build/';
     $cacheFolder = __DIR__ . '/../../build/browscap-ua-test-' . $buildNumber . '/cache/';
     // create build folder if it does not exist
     if (!file_exists(self::$buildFolder)) {
         mkdir(self::$buildFolder, 0777, true);
     }
     if (!file_exists($cacheFolder)) {
         mkdir($cacheFolder, 0777, true);
     }
     $logger = new Logger('browscap');
     $logger->pushHandler(new NullHandler(Logger::DEBUG));
     $buildGenerator = new BuildGenerator($resourceFolder, self::$buildFolder);
     $writerCollectionFactory = new PhpWriterFactory();
     $writerCollection = $writerCollectionFactory->createCollection($logger, self::$buildFolder);
     $buildGenerator->setLogger($logger)->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection);
     $buildGenerator->run($buildNumber, false);
     $cache = new File([File::DIR => $cacheFolder]);
     self::$browscap = new Browscap();
     self::$browscap->setCache($cache)->setLogger($logger);
     self::$browscapUpdater = new BrowscapUpdater();
     self::$browscapUpdater->setCache($cache)->setLogger($logger);
     self::$propertyHolder = new PropertyHolder();
 }
Пример #2
0
 /**
  * This method is called before the first test of this test class is run.
  */
 public static function setUpBeforeClass()
 {
     // First, generate the INI files
     $buildNumber = time();
     $resourceFolder = __DIR__ . '/../../resources/';
     self::$buildFolder = __DIR__ . '/../../build/browscap-ua-test-' . $buildNumber;
     // create build folder if it does not exist
     if (!file_exists(self::$buildFolder)) {
         mkdir(self::$buildFolder, 0777, true);
     }
     $logger = new Logger('browscap');
     $logger->pushHandler(new NullHandler(Logger::DEBUG));
     $buildGenerator = new BuildGenerator($resourceFolder, self::$buildFolder);
     $writerCollectionFactory = new PhpWriterFactory();
     $writerCollection = $writerCollectionFactory->createCollection($logger, self::$buildFolder);
     $buildGenerator->setLogger($logger)->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection);
     $buildGenerator->run('test', false);
     // Now, load an INI file into phpbrowscap\Browscap for testing the UAs
     self::$browscap = new Browscap(self::$buildFolder);
     self::$propertyHolder = new PropertyHolder();
 }
Пример #3
0
 /**
  * fetches a remote file, parses it and writes the result into the cache
  *
  * if the local stored information are in the same version as the remote data no actions are
  * taken
  *
  * @param string      $remoteFile The code for the remote file to load
  * @param string|null $buildFolder
  * @param int|null    $buildNumber
  *
  * @throws \BrowscapPHP\Exception\FileNotFoundException
  * @throws \BrowscapPHP\Helper\Exception
  * @throws \BrowscapPHP\Exception\FetcherException
  */
 public function update($remoteFile = IniLoader::PHP_INI, $buildFolder = null, $buildNumber = null)
 {
     $this->getLogger()->debug('started fetching remote file');
     $converter = new Converter($this->getLogger(), $this->getCache());
     if (class_exists('\\Browscap\\Browscap')) {
         $resourceFolder = 'vendor/browscap/browscap/resources/';
         if (null === $buildNumber) {
             $buildNumber = (int) file_get_contents('vendor/browscap/browscap/BUILD_NUMBER');
         }
         if (null === $buildFolder) {
             $buildFolder = 'resources';
         }
         $buildFolder .= '/browscap-ua-test-' . $buildNumber;
         $iniFile = $buildFolder . '/full_php_browscap.ini';
         mkdir($buildFolder, 0777, true);
         $writerCollectionFactory = new PhpWriterFactory();
         $writerCollection = $writerCollectionFactory->createCollection($this->getLogger(), $buildFolder);
         $buildGenerator = new BuildGenerator($resourceFolder, $buildFolder);
         $buildGenerator->setLogger($this->getLogger())->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection)->run($buildNumber, false);
         $converter->setVersion($buildNumber)->storeVersion()->convertFile($iniFile);
         $filesystem = new Filesystem();
         $filesystem->remove($buildFolder);
     } else {
         if (null === ($cachedVersion = $this->checkUpdate($remoteFile))) {
             // no newer version available
             return;
         }
         $this->getLoader()->setRemoteFilename($remoteFile)->setOptions($this->options)->setLogger($this->getLogger());
         try {
             $content = $this->getLoader()->load();
         } catch (Helper\Exception $e) {
             throw new FetcherException('an error occured while loading remote data', 0, $e);
         }
         if (false === $content) {
             $internalLoader = $this->getLoader()->getLoader();
             $error = error_get_last();
             throw FetcherException::httpError($internalLoader->getUri(), $error['message']);
         }
         $this->getLogger()->debug('finished fetching remote file');
         $this->storeContent($converter, $content, $cachedVersion);
     }
 }