Browscap\Data\Factory\EngineFactory::build PHP Method

build() public method

Load a engines.json file and parse it into the platforms data array
public build ( array $engineData, array $json, string $engineName ) : Engine
$engineData array
$json array
$engineName string
return Browscap\Data\Engine
    public function build(array $engineData, array $json, $engineName)
    {
        if (!isset($engineData['properties'])) {
            $engineData['properties'] = [];
        }
        if (array_key_exists('inherits', $engineData)) {
            $parentName = $engineData['inherits'];
            if (!isset($json['engines'][$parentName])) {
                throw new \UnexpectedValueException('parent Engine "' . $parentName . '" is missing for engine "' . $engineName . '"');
            }
            $parentEngine = $this->build($json['engines'][$parentName], $json, $parentName);
            $parentEngineData = $parentEngine->getProperties();
            $inhEngineProperties = $engineData['properties'];
            foreach ($inhEngineProperties as $name => $value) {
                if (isset($parentEngineData[$name]) && $parentEngineData[$name] === $value) {
                    throw new \UnexpectedValueException('the value for property "' . $name . '" has the same value in the keys "' . $engineName . '" and its parent "' . $engineData['inherits'] . '"');
                }
            }
            $engineData['properties'] = array_merge($parentEngineData, $inhEngineProperties);
        }
        return new Engine($engineData['properties']);
    }

Usage Example

コード例 #1
0
 /**
  * tests the creating of an engine factory
  *
  * @group data
  * @group sourcetest
  */
 public function testBuild()
 {
     $engineData = array('abc' => 'def');
     $json = array();
     $engineName = 'Test';
     self::assertInstanceOf('\\Browscap\\Data\\Engine', $this->object->build($engineData, $json, $engineName));
 }
All Usage Examples Of Browscap\Data\Factory\EngineFactory::build
EngineFactory