/** * 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(); }
/** * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|integer null or 0 if everything went fine, or an error code * * @throws \LogicException When this abstract method is not implemented * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { $loggerHelper = new LoggerHelper(); $logger = $loggerHelper->create($input->getOption('debug')); $logger->info('Build started.'); $buildFolder = $input->getOption('output'); $buildGenerator = new BuildGenerator($input->getOption('resources'), $buildFolder); $writerCollectionFactory = new FullCollectionFactory(); $writerCollection = $writerCollectionFactory->createCollection($logger, $buildFolder); $buildGenerator->setLogger($logger)->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection); $buildGenerator->run($input->getArgument('version')); $logger->info('Build done.'); }
/** * 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(); }
/** * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @throws \LogicException When this abstract method is not implemented * @return null|int null or 0 if everything went fine, or an error code * * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { $leftFilename = $input->getArgument('left'); $rightFilename = $input->getArgument('right'); $debug = $input->getOption('debug'); $loggerHelper = new LoggerHelper(); $logger = $loggerHelper->create($debug); if (!$rightFilename || !file_exists($rightFilename)) { $logger->info('right file not set or invalid - creating right file from resources'); $cacheDir = sys_get_temp_dir() . '/browscap-diff/' . microtime(true) . '/'; $rightFilename = $cacheDir . 'full_php_browscap.ini'; if (!file_exists($cacheDir)) { mkdir($cacheDir, 0777, true); } $buildGenerator = new BuildGenerator($input->getOption('resources'), $cacheDir); $writerCollectionFactory = new FullPhpWriterFactory(); $writerCollection = $writerCollectionFactory->createCollection($logger, $cacheDir); $buildGenerator->setLogger($logger)->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection); $buildGenerator->run($input->getArgument('version'), false); } $generator = new DiffGenerator(); $generator->setLogger($logger)->run($leftFilename, $rightFilename); $logger->info('Diff done.'); }
/** * Executes the current command. * * This method is not abstract because you can use this class * as a concrete class. In this case, instead of defining the * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @throws \Exception * @return null|integer null or 0 if everything went fine, or an error code * * @see setCode() */ protected function execute(InputInterface $input, OutputInterface $output) { $inputFile = $input->getArgument('inputFile'); $mode = $input->getOption('mode'); if (!in_array($mode, array(self::MODE_MATCHED, self::MODE_UNMATCHED))) { throw new \Exception('Mode must be "matched" or "unmatched"'); } if (!file_exists($inputFile)) { throw new \Exception('Input File "' . $inputFile . '" does not exist, or cannot access'); } $cacheDir = sys_get_temp_dir() . '/browscap-grep/' . microtime(true) . '/'; if (!file_exists($cacheDir)) { mkdir($cacheDir, 0777, true); } $debug = $input->getOption('debug'); $loggerHelper = new LoggerHelper(); $this->logger = $loggerHelper->create($debug); $iniFile = $input->getArgument('iniFile'); if (!$iniFile || !file_exists($iniFile)) { $this->logger->info('iniFile Argument not set or invalid - creating iniFile from resources'); $iniFile = $cacheDir . 'full_php_browscap.ini'; $buildGenerator = new BuildGenerator($input->getOption('resources'), $cacheDir); $writerCollectionFactory = new FullPhpWriterFactory(); $writerCollection = $writerCollectionFactory->createCollection($this->logger, $cacheDir); $buildGenerator->setLogger($this->logger)->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection); $buildGenerator->run($input->getArgument('version'), false); } $generator = new GrepGenerator(); $browscap = new Browscap($cacheDir); $browscap->localFile = $iniFile; $generator->setLogger($this->logger)->run($browscap, $inputFile, $mode); $this->logger->info('Grep done.'); }
/** * Generate a build for build number specified * * @param string $buildNumber * @param \Composer\IO\IOInterface $io * @param bool $debug */ public static function createBuild($buildNumber, IOInterface $io = null, $debug = false) { $buildFolder = 'build/build-' . $buildNumber . '/'; $resourceFolder = 'vendor/browscap/browscap/resources/'; if (!file_exists($buildFolder)) { if ($io) { $io->write(' - Creating build folder'); } mkdir($buildFolder, 0775, true); } // Create a logger if ($io) { $io->write(' - Setting up logging'); } $loggerHelper = new LoggerHelper(); $logger = $loggerHelper->create($debug); $collectionCreator = new CollectionCreator(); if ($io) { $io->write(' - Creating writer collection'); } $writerCollectionFactory = new FullCollectionFactory(); $writerCollection = $writerCollectionFactory->createCollection($logger, $buildFolder); // Generate the actual browscap.ini files if ($io) { $io->write(' - Creating actual build'); } $buildGenerator = new BuildGenerator($resourceFolder, $buildFolder); $buildGenerator->setLogger($logger); $buildGenerator->setCollectionCreator($collectionCreator); $buildGenerator->setWriterCollection($writerCollection); $buildGenerator->run($buildNumber, false); if ($io) { $io->write(' - Creating cache'); } $iniFile = $buildFolder . 'full_php_browscap.ini'; $cache = new File(array(File::DIR => 'cache/')); $browscap = new Browscap(); $browscap->setCache($cache)->setLogger($logger); $browscap->convertFile($iniFile); }
/** * 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); } }