/** * Parses a simple xml element and returns an executable string for a layout node * * @param SimpleXMLElement $element * @param CompilerInterface $compiler * @param null|string $parentIdentifier * @param string[] $parentIdentifiers * @return string|string[] */ public function parse(SimpleXMLElement $element, CompilerInterface $compiler, $parentIdentifier = null, $parentIdentifiers = array()) { $attributes = array(); foreach ($element->attributes() as $attribute => $value) { $attributes[$attribute] = (string) $value; } $arguments = array(); $arguments[] = $attributes; if (!empty($attributes['name']) && strpos($attributes['name'], '.') !== 0) { $arguments[] = $attributes['name']; } else { $arguments[] = uniqid('ANONYMOUS_', true); $arguments[0]['_ecomdev_system_option'] = array('is_anonymous' => true); if (!empty($attributes['name'])) { $arguments[0]['_ecomdev_system_option']['anon_suffix'] = substr($attributes['name'], 1); } } $arguments[] = $parentIdentifier; $arguments[] = $parentIdentifiers; if ($parentIdentifier !== null && !in_array($parentIdentifier, $parentIdentifiers, true)) { $parentIdentifiers[] = $parentIdentifier; } if (!empty($attributes['parent'])) { $arguments[2] = $attributes['parent']; // Override parent identifiers, since parent identifier is added to it now $arguments[3] = $parentIdentifiers; } $statements = $compiler->parseElements($element, $arguments[1], $parentIdentifiers); $blockStatements = array(new Expression(sprintf('$this->addItem($item = %s, false)', $this->getClassStatement($arguments)))); foreach (array_unique(array_merge(array($arguments[1], $arguments[2]), $parentIdentifiers)) as $parentBlock) { $blockStatements[] = new Expression(sprintf('$this->addItemRelation($item, %s)', var_export($parentBlock, true))); } return array_merge($blockStatements, $statements); }
/** * Parses a simple xml element and returns an executable string for a layout node * * @param SimpleXMLElement $element * @param \EcomDev_LayoutCompiler_Contract_CompilerInterface $compiler * @param null|string $blockIdentifier * @param string[] $parentIdentifiers * @return string|string[] */ public function parse(SimpleXMLElement $element, CompilerInterface $compiler, $blockIdentifier = null, $parentIdentifiers = array()) { if ($blockIdentifier !== null && !in_array($blockIdentifier, $parentIdentifiers, true)) { $parentIdentifiers[] = $blockIdentifier; } $blockIdentifier = isset($element->attributes()->{$this->idAttribute}) ? (string) $element->attributes()->{$this->idAttribute} : null; return $compiler->parseElements($element, $blockIdentifier, $parentIdentifiers); }
public function testItUpdatesMetadataObjectsFromSource() { $sources = $this->stubSources(array('id_one', 'id_two', 'id_three', 'id_four', 'id_five', 'id_seven')); $metadata = $this->stubMetadataObjects(array('id_one' => array('handle_one', 'handle_two', 'handle_three'), 'id_two' => array('handle_two', 'handle_three', 'handle_five', 'handle_six'), 'id_four' => array('handle_four'), 'id_five' => array('handle_five'), 'id_six' => array('handle_six')), array(2, 1, 1, 2, 1)); $newMetadata = $this->stubMetadataObjects(array('id_two' => array('handle_two'), 'id_three' => array('handle_three'), 'id_four' => array('handle_four', 'handle_five')), 1, false); $expectedMetadata = array('id_one' => $metadata['id_one'], 'id_two' => $newMetadata['id_two'], 'id_three' => $newMetadata['id_three'], 'id_four' => $newMetadata['id_four'], 'id_five' => $metadata['id_five']); $expectedMetadataHandles = array('handle_one' => array('id_one' => $expectedMetadata['id_one']), 'handle_two' => array('id_one' => $expectedMetadata['id_one'], 'id_two' => $expectedMetadata['id_two']), 'handle_three' => array('id_one' => $expectedMetadata['id_one'], 'id_three' => $expectedMetadata['id_three']), 'handle_four' => array('id_four' => $expectedMetadata['id_four']), 'handle_five' => array('id_four' => $expectedMetadata['id_four'], 'id_five' => $expectedMetadata['id_five'])); $testException = new RuntimeException('something wrong is going to happen'); $this->compiler->expects($this->exactly(6))->method('compile')->withConsecutive(array($sources['id_one'], $metadata['id_one']), array($sources['id_two'], $metadata['id_two']), array($sources['id_three'], null), array($sources['id_four'], $metadata['id_four']), array($sources['id_five'], $metadata['id_five']), array($sources['id_seven'], null))->willReturnOnConsecutiveCalls($metadata['id_one'], $newMetadata['id_two'], $newMetadata['id_three'], $newMetadata['id_four'], $metadata['id_five'], $this->throwException($testException)); $errorProcessor = $this->createErrorProcessor($this->index); $errorProcessor->expects($this->once())->method('processException')->with($testException)->willReturnSelf(); $this->index->setLayout($this->layout); $this->index->update($sources); $this->assertAttributeSame($expectedMetadata, 'metadata', $this->index); $this->assertAttributeSame($expectedMetadataHandles, 'metadataByHandle', $this->index); }