/** * Expand the defintion by reference. * * @param Definition $definition * @param array $parameters */ public function expand(Definition $definition, array $parameters = array()) { $expRows = array(); foreach ($definition['rows'] as $rowDefinition) { $rowItems = array(null); if (isset($rowDefinition['with_items'])) { $rowItems = $rowDefinition['with_items']; } $cellDefinitions = array(); if (isset($rowDefinition['cells'])) { // Index the cell definitions.. // This needs to be done because we cannot index them by default // in the definition because column names are dynamic and may validly be // duplicated (e.g. "name": "{{ cell.item }}"). $cellDefinitions = $this->indexCellDefinitions($rowDefinition['cells']); } foreach ($rowItems as $rowItem) { $expRow = $this->expandRow($definition->getColumnNames(), $rowDefinition, $cellDefinitions, $rowItem, $parameters); // no longer need this unset($expRow['with_items']); $expRows[] = $expRow; } } $definition['rows'] = $expRows; }
/** * Merge any included definitions. * * @param Definition */ private function processDefinitionIncludes(Definition $definition) { if (!isset($definition['includes']) || empty($definition['includes'])) { return; } $baseDefinition = array(); $validKeys = array('rows', 'sort', 'classes', 'params', 'includes'); foreach ($definition['includes'] as $include) { $keys = array(); if (count($include) == 2) { list($file, $keys) = $include; } elseif (count($include) == 1) { list($file) = $include; } else { throw new \InvalidArgumentException(sprintf('Invalid number of arguments given for "include" configuration key, got: "%s"', print_r($include, true))); } if (empty($keys)) { $keys = $validKeys; } $filePath = PathUtil::getPath($file, $definition->getBasePath()); $includeDefinition = $this->loadDefinition($filePath); $baseDefinition = $this->mergeDefinition($baseDefinition, $includeDefinition, $keys); } $definition->exchangeArray($this->mergeDefinition($baseDefinition, $definition->getArrayCopy(), $validKeys)); }
private function executePasses(Definition $definition, Element $tableEl) { foreach ($definition->getPasses() as $pass) { $passCellEls = $tableEl->ownerDocument->xpath()->query('//cell[@pass="******"]'); foreach ($passCellEls as $passCellEl) { $rowEls = $tableEl->ownerDocument->xpath()->query('ancestor::row', $passCellEl); $rowEl = $rowEls->item(0); $value = $tableEl->ownerDocument->xpath()->evaluate($passCellEl->nodeValue, $rowEl); $passCellEl->nodeValue = $value; } } }
public function testDefinition() { $definition = new Definition(array('foo' => 'bar'), '/path/to'); $this->assertEquals('bar', $definition['foo']); $this->assertEquals('/path', $definition->getBasePath()); }