Пример #1
0
 /**
  * It should perform an XPath query.
  */
 public function testQuery()
 {
     $this->document->loadXml($this->getXml());
     $nodeList = $this->document->query('//record');
     $this->assertInstanceOf('DOMNodeList', $nodeList);
     $this->assertEquals(2, $nodeList->length);
 }
Пример #2
0
 /**
  * Return a SuiteCollection from a number of PHPBench xml files.
  *
  * @param string[] $files
  *
  * @return SuiteCollection
  */
 public function decodeFiles(array $files)
 {
     // combine into one document.
     //
     $suiteDocument = new Document('phpbench');
     $rootEl = $suiteDocument->createRoot('phpbench');
     foreach ($files as $file) {
         $fileDom = new Document();
         $fileDom->load($file);
         foreach ($fileDom->query('./suite') as $suiteEl) {
             $importedEl = $suiteDocument->importNode($suiteEl, true);
             $rootEl->appendChild($importedEl);
         }
     }
     return $this->decode($suiteDocument);
 }
Пример #3
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);
     }
 }