Browscap\Writer\CsvWriter::renderSectionBody PHP Méthode

renderSectionBody() public méthode

renders all found useragents into a string
public renderSectionBody ( array $section, DataCollection $collection, array $sections = [], string $sectionName = '' ) : CsvWriter
$section array
$collection Browscap\Data\DataCollection
$sections array
$sectionName string
Résultat 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;
    }

Usage Example

Exemple #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\CsvWriter::renderSectionBody