/** * Render the table. * * @param mixed $tableDom * @param mixed $config */ public function render(Document $reportDom, Config $config) { $template = $config['template']; $out = $config['file']; if (!file_exists($template)) { throw new \RuntimeException(sprintf('XSLT template file "%s" does not exist', $template)); } $stylesheetDom = new \DOMDocument('1.0'); $stylesheetDom->load($template); $xsltProcessor = new \XsltProcessor(); $xsltProcessor->importStylesheet($stylesheetDom); $xsltProcessor->setParameter(null, 'title', $config['title']); $xsltProcessor->setParameter(null, 'phpbench-version', PhpBench::VERSION); $xsltProcessor->setParameter(null, 'date', date('Y-m-d H:i:s')); $output = $xsltProcessor->transformToXml($reportDom); if (!$output) { throw new \InvalidArgumentException(sprintf('Could not render report with XSL file "%s"', $template)); } if (null !== $out) { file_put_contents($out, $output); $this->output->writeln('Dumped XSLT report:'); $this->output->writeln($out); } else { $this->output->write($output); } }
/** * Render the table. * * @param mixed $tableDom * @param mixed $config */ public function render(Document $reportDom, Config $config) { $template = $config['template']; $out = strtr($config['file'], ['%report_name%' => $reportDom->firstChild->getAttribute('name')]); if (!file_exists($template)) { throw new \RuntimeException(sprintf('XSLT template file "%s" does not exist', $template)); } foreach ($reportDom->query('.//row') as $rowEl) { $formatterParams = []; foreach ($rowEl->query('./formatter-param') as $paramEl) { $formatterParams[$paramEl->getAttribute('name')] = $paramEl->nodeValue; } foreach ($rowEl->query('./cell') as $cellEl) { $value = $cellEl->nodeValue; if ('' !== $value && $cellEl->hasAttribute('class')) { $classes = explode(' ', $cellEl->getAttribute('class')); $value = $this->formatter->applyClasses($classes, $value, $formatterParams); $cellEl->nodeValue = $value; } } } $stylesheetDom = new \DOMDocument('1.0'); $stylesheetDom->load($template); $xsltProcessor = new \XsltProcessor(); $xsltProcessor->importStylesheet($stylesheetDom); $xsltProcessor->setParameter(null, 'title', $config['title']); $xsltProcessor->setParameter(null, 'phpbench-version', PhpBench::VERSION); $xsltProcessor->setParameter(null, 'date', date('Y-m-d H:i:s')); $output = $xsltProcessor->transformToXml($reportDom); if (!$output) { throw new \InvalidArgumentException(sprintf('Could not render report with XSL file "%s"', $template)); } if ($out) { file_put_contents($out, $output); $this->output->writeln('Dumped XSLT report:'); $this->output->writeln($out); } else { $this->output->write($output); } }
public function render(Document $reportsDocument, Config $config) { $this->output->writeln('Report XML (debug):'); $this->output->writeln($reportsDocument->dump()); }
public function render(Document $reportsDocument, array $config) { $this->output->writeln('Report XML (debug):'); $this->output->writeln($reportsDocument->saveXml()); }