/** * Iterate over the definition and determine the number of columns and compiler * passes. * * @param Definition */ private function processMetadata(Definition $definition, $sourceDom = null) { $columns = array(); $passes = array(); if ($sourceDom) { $xpath = new \DOMXpath($sourceDom); $this->xpathResolver->registerXPathFunctions($xpath); } foreach ($definition['rows'] as &$rowDefinition) { foreach ($rowDefinition['cells'] as &$cellDefinition) { $cellName = $cellDefinition['name']; if (isset($cellDefinition['pass'])) { $passes[] = $cellDefinition['pass']; } // if an expression is given to with_items then we need to query // the source document to evaluate the item names. if (isset($cellDefinition['with_items']['selector'])) { if (null === $sourceDom) { throw new \RuntimeException('You must pass the source document to the loader in order to use `with_items_expr`'); } $itemsExpr = $cellDefinition['with_items']; $selector = $this->xpathResolver->replaceFunctions($itemsExpr['selector']); $nodes = $xpath->query($selector); $items = array(); foreach ($nodes as $node) { // todo: Support keys ? $value = $xpath->evaluate($itemsExpr['value'], $node); $items[] = $value; } $cellDefinition['with_items'] = $items; } $cellItems = array(null); if (isset($cellDefinition['with_items'])) { $cellItems = $cellDefinition['with_items']; } foreach ($cellItems as $cellItem) { $evaledCellName = $this->tokenReplacer->replaceTokens($cellName, null, $cellItem); $columns[$evaledCellName] = $evaledCellName; } } } sort($passes); $definition->setMetadata(array_values($columns), $passes); }
private function registerTabular(Container $container) { $container->register('tabular.xpath_resolver', function () { require_once __DIR__ . '/../Dom/xpath_functions.php'; $resolver = new XPathResolver(); $resolver->registerFunction('parameters_to_json', 'PhpBench\\Dom\\functions\\parameters_to_json'); $resolver->registerFunction('class_name', 'PhpBench\\Dom\\functions\\class_name'); $resolver->registerFunction('join_node_values', 'PhpBench\\Dom\\functions\\join_node_values'); $resolver->registerFunction('kde_mode', 'PhpBench\\Dom\\functions\\join_node_values'); $resolver->registerFunction('suite', 'PhpBench\\Dom\\functions\\suite'); return $resolver; }); $container->register('tabular.table_builder', function (Container $container) { return new TableBuilder($container->get('tabular.xpath_resolver')); }); $container->register('tabular.formatter.registry', function (Container $container) { $registry = new ArrayRegistry(); $registry->register('printf', new PrintfFormat()); $registry->register('balance', new BalanceFormat()); $registry->register('number', new NumberFormat()); $registry->register('truncate', new TruncateFormat()); $registry->register('json_format', new JSONFormat()); $registry->register('time', new TimeFormat($container->get('benchmark.time_unit'))); return $registry; }); $container->register('tabular.formatter', function (Container $container) { return new Formatter($container->get('tabular.formatter.registry')); }); $container->register('tabular', function (Container $container) { return new Tabular($container->get('tabular.table_builder'), $container->get('tabular.definition_loader'), $container->get('tabular.formatter'), $container->get('tabular.expander')); }); $container->register('tabular.definition_loader', function (Container $container) { return new Loader($container->get('json_schema.validator')); }); $container->register('tabular.expander', function (Container $container) { return new Expander(); }); }
private function registerTabular(Container $container) { $container->register('tabular.xpath_resolver', function () { $resolver = new XPathResolver(); $resolver->registerFunction('parameters_to_json', 'PhpBench\\Report\\Dom\\functions\\parameters_to_json'); $resolver->registerFunction('class_name', 'PhpBench\\Report\\Dom\\functions\\class_name'); return $resolver; }); $container->register('tabular.table_builder', function (Container $container) { return new TableBuilder($container->get('tabular.xpath_resolver')); }); $container->register('tabular.formatter.registry', function (Container $container) { $registry = new ArrayRegistry(); $registry->register('printf', new PrintfFormat()); $registry->register('balance', new BalanceFormat()); $registry->register('number', new NumberFormat()); return $registry; }); $container->register('tabular.formatter', function (Container $container) { return new Formatter($container->get('tabular.formatter.registry')); }); $container->register('tabular', function (Container $container) { return new Tabular($container->get('tabular.table_builder'), $container->get('tabular.definition_loader'), $container->get('tabular.formatter'), $container->get('tabular.expander')); }); $container->register('tabular.definition_loader', function (Container $container) { return new Loader($container->get('json_schema.validator')); }); $container->register('tabular.expander', function (Container $container) { return new Expander(); }); }