convertFile() public method

reads and parses an ini file and writes the results into the cache
public convertFile ( string $iniFile )
$iniFile string
コード例 #1
0
 protected function getParserWithWarmCache($type)
 {
     $filename = 'php_browscap.ini';
     if ($type != '') {
         $filename = $type . '_' . $filename;
     }
     $cache = new \WurflCache\Adapter\Memory();
     $browscap = new Browscap();
     $browscap->setCache($cache);
     $updater = new BrowscapUpdater();
     $updater->setCache($cache);
     $updater->convertFile('tests/resources/browscap/' . $filename);
     return $browscap;
 }
コード例 #2
0
ファイル: UserAgentsTest.php プロジェクト: browscap/browscap
 /**
  * @dataProvider userAgentDataProviderLite
  * @coversNothing
  *
  * @param string $userAgent
  * @param array  $expectedProperties
  *
  * @throws \Exception
  * @throws \BrowscapPHP\Exception
  *
  * @group intergration
  * @group useragenttest
  * @group lite
  */
 public function testUserAgentsLite($userAgent, $expectedProperties)
 {
     if (!is_array($expectedProperties) || !count($expectedProperties)) {
         self::markTestSkipped('Could not run test - no properties were defined to test');
     }
     static $updatedLiteCache = false;
     if (!$updatedLiteCache) {
         self::$browscapUpdater->getCache()->flush();
         self::$browscapUpdater->convertFile(self::$buildFolder . '/lite_php_browscap.ini');
         $updatedLiteCache = true;
     }
     $actualProps = (array) self::$browscap->getBrowser($userAgent);
     foreach ($expectedProperties as $propName => $propValue) {
         if (!self::$propertyHolder->isOutputProperty($propName)) {
             continue;
         }
         if (!self::$propertyHolder->isLiteModeProperty($propName)) {
             continue;
         }
         $propName = strtolower($propName);
         self::assertArrayHasKey($propName, $actualProps, 'Actual result does not have "' . $propName . '" property');
         self::assertSame($propValue, $actualProps[$propName], 'Expected actual "' . $propName . '" to be "' . $propValue . '" (was "' . $actualProps[$propName] . '"; used pattern: ' . $actualProps['browser_name_pattern'] . ')');
     }
 }
コード例 #3
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loggerHelper = new LoggerHelper();
     $logger = $loggerHelper->create($input->getOption('debug'));
     $logger->info('initializing converting process');
     $browscap = new BrowscapUpdater();
     $browscap->setLogger($logger)->setCache($this->getCache($input));
     $logger->info('started converting local file');
     $file = $input->getArgument('file') ? $input->getArgument('file') : $this->defaultIniFile;
     $browscap->convertFile($file);
     $logger->info('finished converting local file');
 }
コード例 #4
0
    /**
     *
     */
    public function testConvertFile()
    {
        $content = ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Browscap Version

[GJK_Browscap_Version]
Version=5031
Released=Mon, 30 Jun 2014 17:55:58 +0200
Format=ASP
Type=

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DefaultProperties

[DefaultProperties]

Comment=DefaultProperties
Browser=DefaultProperties
Version=0.0
MajorVer=0
MinorVer=0
Platform=unknown
Platform_Version=unknown
Alpha=false
Beta=false
Win16=false
Win32=false
Win64=false
Frames=false
IFrames=false
Tables=false
Cookies=false
BackgroundSounds=false
JavaScript=false
VBScript=false
JavaApplets=false
ActiveXControls=false
isMobileDevice=false
isTablet=false
isSyndicationReader=false
Crawler=false
CssVersion=0
AolVersion=0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ask

[Ask]

Parent=DefaultProperties
Comment=Ask
Browser=Ask
Frames=1
IFrames=1
Tables=1
Crawler=1
Version=0.0
MajorVer=0
MinorVer=0
Platform=unknown
Platform_Version=unknown
Alpha=
Beta=
Win16=
Win32=
Win64=
Cookies=
BackgroundSounds=
JavaScript=
VBScript=
JavaApplets=
ActiveXControls=
isMobileDevice=
isTablet=
isSyndicationReader=
CssVersion=0
AolVersion=0

[Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)]

Parent=Ask
Browser=Teoma
Comment=Ask
Version=0.0
MajorVer=0
MinorVer=0
Platform=unknown
Platform_Version=unknown
Alpha=
Beta=
Win16=
Win32=
Win64=
Frames=1
IFrames=1
Tables=1
Cookies=
BackgroundSounds=
JavaScript=
VBScript=
JavaApplets=
ActiveXControls=
isMobileDevice=
isTablet=
isSyndicationReader=
Crawler=1
CssVersion=0
AolVersion=0
';
        $structure = ['test.ini' => $content];
        vfsStream::setup(self::STORAGE_DIR, null, $structure);
        $cache = new Memory();
        $this->object->setCache($cache);
        $this->object->convertFile(vfsStream::url(self::STORAGE_DIR . DIRECTORY_SEPARATOR . 'test.ini'));
        self::assertSame(5031, $this->object->getCache()->getVersion());
    }