Browscap\Writer\IniWriter::renderSectionBody PHP Метод

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

renders all found useragents into a string
public renderSectionBody ( array $section, DataCollection $collection, array $sections = [], string $sectionName = '' ) : IniWriter
$section array
$collection Browscap\Data\DataCollection
$sections array
$sectionName string
Результат IniWriter
    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);
        }
        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;
                    }
                }
            }
            fputs($this->file, $this->getFormatter()->formatPropertyName($property) . '=' . $this->getFormatter()->formatPropertyValue($section[$property], $property) . PHP_EOL);
        }
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * tests rendering the body of one section
  *
  * @group writer
  * @group sourcetest
  */
 public function testRenderSectionBodyIfSilent()
 {
     $this->object->setSilent(true);
     $section = ['Test' => 1, 'isTest' => true, 'abc' => 'bcd'];
     $collection = $this->createMock(\Browscap\Data\DataCollection::class);
     self::assertSame($this->object, $this->object->renderSectionBody($section, $collection));
     self::assertSame('', file_get_contents($this->file));
 }
All Usage Examples Of Browscap\Writer\IniWriter::renderSectionBody