/**
  * Gets the browscap data of the used source type
  *
  * @return string
  */
 public function getBrowscapSource()
 {
     $type = Browscap::getParser()->getSourceType();
     $url = str_replace('%t', urlencode($type), $this->getBrowscapSourceUrl());
     return $this->getRemoteData($url);
 }
Beispiel #2
0
 /**
  * @covers ::update
  *
  * @throws ParserConfigurationException
  * @throws ParserRuntimeException
  * @throws SourceUnavailableException
  */
 public function testForcedUpdate()
 {
     $iniFile = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'lite_php_browscap.ini';
     $source = new File($iniFile);
     $browscap = new Browscap();
     $browscap->getParser()->setSource($source);
     $browscap->update(true);
 }
Beispiel #3
0
 /**
  * Gets the main/version cache directory
  *
  * @param boolean $with_version
  * @param bool $create_dir
  * @return string
  */
 public static function getCacheDirectory($with_version = false, $create_dir = false)
 {
     // get sub directory name, depending on the data set type
     // (one sub directory for each data set type and version)
     switch (Browscap::getDatasetType()) {
         case Browscap::DATASET_TYPE_SMALL:
             $subDirName = 'smallbrowscap';
             break;
         case Browscap::DATASET_TYPE_LARGE:
             $subDirName = 'largebrowscap';
             break;
         default:
             $subDirName = 'browscap';
     }
     if (static::$cache_dir === null) {
         static::setCacheDirectory(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'browscap');
     }
     $path = static::$cache_dir;
     if ($with_version === true) {
         $path .= DIRECTORY_SEPARATOR . $subDirName;
         $path .= '_v' . Browscap::getParser()->getVersion();
         $path .= '_' . Browscap::VERSION;
     }
     if ($create_dir === true && !file_exists($path)) {
         mkdir($path, 0777, true);
     }
     return $path;
 }
Beispiel #4
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  * @throws ParserConfigurationException
  * @throws ParserRuntimeException
  * @throws SourceConditionNotSatisfiedException
  * @throws SourceUnavailableException
  * @throws UnexpectedValueException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $browscap = new Browscap();
     // Set source
     $source = null;
     if ($input->getOption('ini-php')) {
         $source = new PhpSetting();
     } elseif ($input->getOption('ini-load')) {
         $type = Type::STANDARD;
         switch ($input->getOption('ini-load')) {
             case 'lite':
                 $type = Type::LITE;
                 break;
             case 'full':
                 $type = Type::FULL;
                 break;
         }
         $source = new BrowscapOrg($type);
     } elseif ($input->getOption('ini-file')) {
         $file = (string) $input->getOption('ini-file');
         $source = new File($file);
     }
     if ($source !== null) {
         $browscap->getParser()->setSource($source);
     }
     // Set filter
     $filter = null;
     if ($input->getOption('filter-allowed')) {
         $properties = (array) $input->getOption('filter-allowed');
         $filter = new Allowed($properties);
     } elseif ($input->getOption('filter-disallowed')) {
         $properties = (array) $input->getOption('filter-disallowed');
         $filter = new Disallowed($properties);
     }
     if ($filter !== null) {
         $browscap->getParser()->setPropertyFilter($filter);
     }
     // Set data directory
     if ($input->getOption('dir')) {
         /** @var Parser $parser */
         $parser = $browscap->getParser();
         $parser->setDataDirectory((string) $input->getOption('dir'));
     }
     // Force an update?
     $force = false;
     if ($input->getOption('force')) {
         $force = true;
     }
     // Process update
     $output->writeln('Processing update...');
     $updated = $browscap->update($force);
     // Output result
     $version = $browscap->getParser()->getReader()->getVersion();
     $type = $browscap->getParser()->getReader()->getType();
     $name = Type::getName($type);
     if ($updated === true) {
         $output->writeln(sprintf('Browscap data successfully updated. New version: %s (%s)', $version, $name));
     } else {
         $output->writeln(sprintf('Nothing to update. Current version: %s (%s)', $version, $name));
     }
 }