PhpBench\Serializer\XmlEncoder::encode PHP Метод

encode() публичный Метод

Encode a Suite object into a XML document.
public encode ( SuiteCollection $suiteCollection ) : PhpBench\Dom\Document
$suiteCollection PhpBench\Model\SuiteCollection
Результат PhpBench\Dom\Document
    public function encode(SuiteCollection $suiteCollection)
    {
        $dom = new Document();
        $rootEl = $dom->createRoot('phpbench');
        $rootEl->setAttribute('version', PhpBench::VERSION);
        foreach ($suiteCollection->getSuites() as $suite) {
            $suiteEl = $rootEl->appendElement('suite');
            $suiteEl->setAttribute('context', $suite->getContextName());
            $suiteEl->setAttribute('date', $suite->getDate()->format('Y-m-d H:i:s'));
            $suiteEl->setAttribute('config-path', $suite->getConfigPath());
            $suiteEl->setAttribute('uuid', $suite->getUuid());
            $envEl = $suiteEl->appendElement('env');
            foreach ($suite->getEnvInformations() as $information) {
                $infoEl = $envEl->appendElement($information->getName());
                foreach ($information as $key => $value) {
                    $infoEl->setAttribute($key, $value);
                }
            }
            foreach ($suite->getBenchmarks() as $benchmark) {
                $this->processBenchmark($benchmark, $suiteEl);
            }
        }
        return $dom;
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function archive(OutputInterface $output)
 {
     $driver = $this->storageRegistry->getService();
     if (!$this->filesystem->exists($this->archivePath)) {
         $this->filesystem->mkdir($this->archivePath);
     }
     $runIds = [];
     foreach ($driver->history() as $entry) {
         $runIds[] = $entry->getRunId();
     }
     $output->writeln(sprintf('Archiving "%s" suites', count($runIds)));
     foreach ($runIds as $index => $runId) {
         $filename = $runId . '.xml';
         $path = sprintf('%s/%s', $this->archivePath, $filename);
         if ($this->filesystem->exists($path)) {
             $this->writeProgress($output, $index, count($runIds), 'S');
             continue;
         }
         $this->writeProgress($output, $index, count($runIds), '.');
         $collection = $driver->fetch($runId);
         $document = $this->xmlEncoder->encode($collection);
         $document->save($path);
     }
     $output->writeln(PHP_EOL);
 }
All Usage Examples Of PhpBench\Serializer\XmlEncoder::encode