addDevicesFile() 공개 메소드

Load a devices.json file and parse it into the platforms data array
public addDevicesFile ( string $src ) : DataCollection
$src string Name of the file
리턴 DataCollection
예제 #1
0
 /**
  * Create and populate a data collection object from a resource folder
  *
  * @param string $resourceFolder
  *
  * @throws \LogicException
  * @return \Browscap\Data\DataCollection
  */
 public function createDataCollection($resourceFolder)
 {
     if (null === $this->collection) {
         throw new \LogicException('An instance of \\Browscap\\Data\\DataCollection is required for this function. ' . 'Please set it with setDataCollection');
     }
     $this->getLogger()->debug('add platform file');
     $this->collection->addDevicesFile($resourceFolder . '/devices.json')->addPlatformsFile($resourceFolder . '/platforms.json')->addEnginesFile($resourceFolder . '/engines.json')->addDefaultProperties($resourceFolder . '/core/default-properties.json')->addDefaultBrowser($resourceFolder . '/core/default-browser.json');
     $uaSourceDirectory = $resourceFolder . '/user-agents';
     $iterator = new \RecursiveDirectoryIterator($uaSourceDirectory);
     foreach (new \RecursiveIteratorIterator($iterator) as $file) {
         /** @var $file \SplFileInfo */
         if (!$file->isFile() || $file->getExtension() != 'json') {
             continue;
         }
         $this->getLogger()->debug('add source file ' . $file->getPathname());
         $this->collection->addSourceFile($file->getPathname());
     }
     return $this->collection;
 }
예제 #2
0
 /**
  * @expectedException \OutOfBoundsException
  * @expectedExceptionMessage Device "NotExists" does not exist in data, available devices:
  *
  * @group data
  * @group sourcetest
  */
 public function testGetDeviceThrowsExceptionIfDeviceDoesNotExist()
 {
     $this->object->addDevicesFile($this->getDevicesJsonFixture());
     $this->object->getDevice('NotExists');
 }