PhpBench\Report\Generator\TableGenerator::generateDocument PHP Méthode

generateDocument() private méthode

Generate the report DOM document to pass to the report renderer.
private generateDocument ( array $tables, Config $config ) : PhpBench\Dom\Document
$tables array
$config PhpBench\Registry\Config
Résultat PhpBench\Dom\Document
    private function generateDocument(array $tables, Config $config)
    {
        $document = new Document();
        $reportsEl = $document->createRoot('reports');
        $reportsEl->setAttribute('name', 'table');
        $reportEl = $reportsEl->appendElement('report');
        $classMap = array_merge($this->classMap, $config['class_map']);
        if (isset($config['title'])) {
            $reportEl->setAttribute('title', $config['title']);
        }
        if (isset($config['description'])) {
            $reportEl->appendElement('description', $config['description']);
        }
        foreach ($tables as $breakHash => $table) {
            $tableEl = $reportEl->appendElement('table');
            // Build the col(umn) definitions.
            foreach ($table as $row) {
                $colsEl = $tableEl->appendElement('cols');
                foreach ($row->getNames() as $cellIndex => $colName) {
                    $colEl = $colsEl->appendElement('col');
                    $colEl->setAttribute('name', $colName);
                    // column labels are the column names by default.
                    // the user may override by column name or column index.
                    $colLabel = $colName;
                    if (isset($config['labels'][$colName])) {
                        $colLabel = $config['labels'][$colName];
                    } elseif (isset($config['labels'][$cellIndex])) {
                        $colLabel = $config['labels'][$cellIndex];
                    }
                    $colEl->setAttribute('label', $colLabel);
                }
                break;
            }
            if ($breakHash) {
                $tableEl->setAttribute('title', $breakHash);
            }
            $groupEl = $tableEl->appendElement('group');
            $groupEl->setAttribute('name', 'body');
            foreach ($table as $row) {
                $rowEl = $groupEl->appendElement('row');
                // apply formatter options
                foreach ($row->getFormatParams() as $paramName => $paramValue) {
                    $paramEl = $rowEl->appendElement('formatter-param', $paramValue);
                    $paramEl->setAttribute('name', $paramName);
                }
                foreach ($row as $key => $value) {
                    $cellEl = $rowEl->appendElement('cell', $value);
                    $cellEl->setAttribute('name', $key);
                    if (isset($classMap[$key])) {
                        $cellEl->setAttribute('class', implode(' ', $classMap[$key]));
                    }
                }
            }
        }
        return $document;
    }