Browscap\Data\DataCollection::addDevicesFile PHP Метод

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
    public function addDevicesFile($src)
    {
        $json = $this->loadFile($src);
        $deviceFactory = new Factory\DeviceFactory();
        foreach ($json['devices'] as $deviceName => $deviceData) {
            if (!isset($deviceData['properties']) && !isset($deviceData['inherits'])) {
                throw new \UnexpectedValueException('required attibute "properties" is missing');
            }
            $this->devices[$deviceName] = $deviceFactory->build($deviceData, $json, $deviceName);
        }
        $this->divisionsHaveBeenSorted = false;
        return $this;
    }

Usage Example

Пример #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;
 }
All Usage Examples Of Browscap\Data\DataCollection::addDevicesFile