Browscap\Data\Expander::expandProperties PHP Метод

expandProperties() приватный Метод

expands all properties for all useragents to make sure all properties are set and make it possible to skip incomplete properties and remove duplicate definitions
private expandProperties ( array $allInputDivisions ) : array
$allInputDivisions array
Результат array
    private function expandProperties(array $allInputDivisions)
    {
        $this->getLogger()->debug('expand all properties');
        $allDivisions = [];
        $ua = $this->collection->getDefaultProperties()->getUserAgents();
        $defaultproperties = $ua[0]['properties'];
        foreach (array_keys($allInputDivisions) as $key) {
            $this->getLogger()->debug('expand all properties for key "' . $key . '"');
            $userAgent = $key;
            $parents = [$userAgent];
            while (isset($allInputDivisions[$userAgent]['Parent'])) {
                if ($userAgent === $allInputDivisions[$userAgent]['Parent']) {
                    break;
                }
                $parents[] = $allInputDivisions[$userAgent]['Parent'];
                $userAgent = $allInputDivisions[$userAgent]['Parent'];
            }
            unset($userAgent);
            $parents = array_reverse($parents);
            $browserData = $defaultproperties;
            $properties = $allInputDivisions[$key];
            foreach ($parents as $parent) {
                if (!isset($allInputDivisions[$parent])) {
                    continue;
                }
                if (!is_array($allInputDivisions[$parent])) {
                    throw new \UnexpectedValueException('Parent "' . $parent . '" is not an array for key "' . $key . '"');
                }
                if ($key !== $parent && isset($allInputDivisions[$parent]['sortIndex']) && isset($properties['sortIndex']) && $allInputDivisions[$parent]['division'] !== $properties['division']) {
                    if ($allInputDivisions[$parent]['sortIndex'] >= $properties['sortIndex']) {
                        throw new \UnexpectedValueException('sorting not ready for key "' . $key . '"');
                    }
                }
                $browserData = array_merge($browserData, $allInputDivisions[$parent]);
            }
            array_pop($parents);
            $browserData['Parents'] = implode(',', $parents);
            unset($parents);
            foreach (array_keys($browserData) as $propertyName) {
                $properties[$propertyName] = $this->trimProperty($browserData[$propertyName]);
            }
            unset($browserData);
            $allDivisions[$key] = $properties;
            if (!isset($properties['Version'])) {
                throw new \UnexpectedValueException('Version property not found for key "' . $key . '"');
            }
            $completeVersions = explode('.', $properties['Version'], 2);
            if (!isset($properties['MajorVer']) || '#MAJORVER#' === $properties['MajorVer']) {
                $properties['MajorVer'] = (string) $completeVersions[0];
            } elseif ($properties['MajorVer'] !== (string) $completeVersions[0]) {
                throw new \UnexpectedValueException('MajorVersion from properties does not match with Version for key "' . $key . '", "' . $properties['MajorVer'] . '" was defined, "' . (string) $completeVersions[0] . '" was expected');
            }
            if (isset($completeVersions[1])) {
                $minorVersion = (string) $completeVersions[1];
            } else {
                $minorVersion = '0';
            }
            if (!isset($properties['MinorVer']) || '#MINORVER#' === $properties['MinorVer']) {
                $properties['MinorVer'] = $minorVersion;
            } elseif ($properties['MinorVer'] !== $minorVersion) {
                throw new \UnexpectedValueException('MinorVersion from properties does not match with Version for key "' . $key . '", "' . $properties['MinorVer'] . '" was defined, "' . $minorVersion . '" was expected');
            }
            $allDivisions[$key] = $properties;
        }
        return $allDivisions;
    }