getDefaultProperties() 공개 메소드

Get the divisions array containing UA data
public getDefaultProperties ( ) : Division
리턴 Division
예제 #1
0
 /**
  * checks if the default properties are added sucessfully
  *
  * @group data
  * @group sourcetest
  */
 public function testAddDefaultProperties()
 {
     self::assertSame($this->object, $this->object->addDefaultProperties(__DIR__ . '/../../fixtures/ua/default-properties.json'));
     $division = $this->object->getDefaultProperties();
     self::assertInstanceOf('\\Browscap\\Data\\Division', $division);
     self::assertSame('DefaultProperties', $division->getName());
 }
예제 #2
0
 /**
  * renders all found useragents into a string
  *
  * @param string[]                      $section
  * @param \Browscap\Data\DataCollection $collection
  * @param array[]                       $sections
  * @param string                        $sectionName
  *
  * @throws \InvalidArgumentException
  * @return XmlWriter
  */
 public function renderSectionBody(array $section, DataCollection $collection, array $sections = array(), $sectionName = '')
 {
     if ($this->isSilent()) {
         return $this;
     }
     $division = $collection->getDefaultProperties();
     $ua = $division->getUserAgents();
     $defaultproperties = $ua[0]['properties'];
     $properties = array_merge(array('Parent'), array_keys($defaultproperties));
     foreach ($section as $property => $propertyValue) {
         $section[$property] = trim($propertyValue);
     }
     foreach ($properties as $property) {
         if (!isset($section[$property])) {
             continue;
         }
         if (!isset($this->outputProperties[$property])) {
             $this->outputProperties[$property] = $this->getFilter()->isOutputProperty($property, $this);
         }
         if (!$this->outputProperties[$property]) {
             continue;
         }
         fputs($this->file, '<item name="' . $this->getFormatter()->formatPropertyName($property) . '" value="' . $this->getFormatter()->formatPropertyValue($section[$property], $property) . '"/>' . PHP_EOL);
     }
     return $this;
 }
예제 #3
0
 /**
  * renders all found useragents into a string
  *
  * @param string[]                      $section
  * @param \Browscap\Data\DataCollection $collection
  * @param array[]                       $sections
  * @param string                        $sectionName
  *
  * @throws \InvalidArgumentException
  * @return JsonWriter
  */
 public function renderSectionBody(array $section, DataCollection $collection, array $sections = [], $sectionName = '')
 {
     if ($this->isSilent()) {
         return $this;
     }
     $division = $collection->getDefaultProperties();
     $ua = $division->getUserAgents();
     $defaultproperties = $ua[0]['properties'];
     $properties = array_merge(['Parent'], array_keys($defaultproperties));
     foreach ($defaultproperties as $propertyName => $propertyValue) {
         $defaultproperties[$propertyName] = $this->expander->trimProperty($propertyValue);
     }
     $propertiesToOutput = [];
     foreach ($properties as $property) {
         if (!isset($section[$property])) {
             continue;
         }
         if (!isset($this->outputProperties[$property])) {
             $this->outputProperties[$property] = $this->getFilter()->isOutputProperty($property, $this);
         }
         if (!$this->outputProperties[$property]) {
             continue;
         }
         if (isset($section['Parent']) && 'Parent' !== $property) {
             if ('DefaultProperties' === $section['Parent'] || !isset($sections[$section['Parent']])) {
                 if (isset($defaultproperties[$property]) && $defaultproperties[$property] === $section[$property]) {
                     continue;
                 }
             } else {
                 $parentProperties = $sections[$section['Parent']];
                 if (isset($parentProperties[$property]) && $parentProperties[$property] === $section[$property]) {
                     continue;
                 }
             }
         }
         $propertiesToOutput[$property] = $section[$property];
     }
     fputs($this->file, $this->getFormatter()->formatPropertyValue(json_encode($propertiesToOutput), 'Comment'));
     return $this;
 }
예제 #4
0
 /**
  * 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
  *
  * @param array $allInputDivisions
  *
  * @throws \UnexpectedValueException
  * @return array
  */
 private function expandProperties(array $allInputDivisions)
 {
     $this->getLogger()->debug('expand all properties');
     $allDivisions = array();
     $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 = array($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;
 }
예제 #5
0
 /**
  * renders all found useragents into a string
  *
  * @param string[]                      $section
  * @param \Browscap\Data\DataCollection $collection
  * @param array[]                       $sections
  * @param string                        $sectionName
  *
  * @throws \InvalidArgumentException
  * @return CsvWriter
  */
 public function renderSectionBody(array $section, DataCollection $collection, array $sections = [], $sectionName = '')
 {
     if ($this->isSilent()) {
         return $this;
     }
     $division = $collection->getDefaultProperties();
     $ua = $division->getUserAgents();
     $defaultproperties = $ua[0]['properties'];
     $properties = array_merge(['PropertyName', 'MasterParent', 'LiteMode', 'Parent'], array_keys($defaultproperties));
     $values = [];
     $section['PropertyName'] = $sectionName;
     $section['MasterParent'] = $this->detectMasterParent($sectionName, $section);
     if (in_array($sectionName, ['DefaultProperties', '*'])) {
         $section['LiteMode'] = 'true';
     } else {
         $section['LiteMode'] = !isset($section['lite']) || !$section['lite'] ? 'false' : 'true';
     }
     foreach ($properties as $property) {
         if (!isset($this->outputProperties[$property])) {
             $this->outputProperties[$property] = $this->getFilter()->isOutputProperty($property, $this);
         }
         if (!$this->outputProperties[$property]) {
             continue;
         }
         if (isset($section[$property])) {
             $value = $section[$property];
         } else {
             $value = '';
         }
         $values[] = $this->getFormatter()->formatPropertyValue($value, $property);
     }
     fputs($this->file, implode(',', $values) . PHP_EOL);
     return $this;
 }