Load a devices.json file and parse it into the platforms data array
public addDevicesFile ( string $src ) : |
||
$src | string | Name of the file |
return |
/** * 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; }
/** * @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'); }