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

addPlatformsFile() публичный Метод

Load a platforms.json file and parse it into the platforms data array
public addPlatformsFile ( string $src ) : DataCollection
$src string Name of the file
Результат DataCollection
    public function addPlatformsFile($src)
    {
        $json = $this->loadFile($src);
        if (!isset($json['platforms'])) {
            throw new \UnexpectedValueException('required "platforms" structure is missing');
        }
        $platformFactory = new Factory\PlatformFactory();
        foreach (array_keys($json['platforms']) as $platformName) {
            $platformData = $json['platforms'][$platformName];
            if (!isset($platformData['match'])) {
                throw new \UnexpectedValueException('required attibute "match" is missing');
            }
            if (!isset($platformData['properties']) && !isset($platformData['inherits'])) {
                throw new \UnexpectedValueException('required attibute "properties" is missing');
            }
            $this->platforms[$platformName] = $platformFactory->build($platformData, $json, $platformName);
        }
        $this->divisionsHaveBeenSorted = false;
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * tests getting an exiting platform
  *
  * @group data
  * @group sourcetest
  */
 public function testGetPlatform()
 {
     $this->object->addPlatformsFile($this->getPlatformsJsonFixture());
     self::assertInternalType('array', $this->object->getPlatforms());
     $platform = $this->object->getPlatform('Platform1');
     self::assertInstanceOf('\\Browscap\\Data\\Platform', $platform);
     $properties = $platform->getProperties();
     self::assertInternalType('array', $properties);
     self::assertArrayHasKey('Platform', $properties);
     self::assertSame('Platform1', $properties['Platform']);
 }