applyClasses() public method

Parameters can be given: parameters are used to replcae any tokens used in the format options; this is required when options should be overridden on a per-subject basis.
public applyClasses ( array $classNames, string $value, array $params = [] ) : string
$classNames array
$value string
$params array
return string
Exemplo n.º 1
0
 protected function renderTableElement(Element $tableEl, $config)
 {
     $rows = [];
     $colNames = [];
     foreach ($tableEl->query('.//col') as $colEl) {
         $colNames[] = $colEl->getAttribute('label');
     }
     foreach ($tableEl->query('.//row') as $rowEl) {
         $row = [];
         $formatterParams = [];
         foreach ($rowEl->query('./formatter-param') as $paramEl) {
             $formatterParams[$paramEl->getAttribute('name')] = $paramEl->nodeValue;
         }
         foreach ($rowEl->query('.//cell') as $cellEl) {
             $colName = $cellEl->getAttribute('name');
             $value = $cellEl->nodeValue;
             if ('' !== $value && $cellEl->hasAttribute('class')) {
                 $classes = explode(' ', $cellEl->getAttribute('class'));
                 $value = $this->formatter->applyClasses($classes, $value, $formatterParams);
             }
             $row[$colName] = $value;
         }
         $rows[] = $row;
     }
     $table = $this->createTable();
     // style only supported in Symfony > 2.4
     if (method_exists($table, 'setStyle')) {
         $table->setStyle($config['table_style']);
     }
     $table->setHeaders($colNames);
     $table->setRows($rows);
     $this->renderTable($table);
     $this->output->writeln('');
 }
Exemplo n.º 2
0
 /**
  * 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);
     }
 }