/** * 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); }