public function execute(Node $node, Context $context) { if ($node instanceof MacroReferenceNode) { $path = $node->getMacroPath(); // Provided that users might want some things hardcoded, everything // under the 'macro' root node will be considered as macros if (false === strpos($path, Path::SEP)) { $path = 'macro' . Path::SEP . $path; } $macro = (new Path($path))->find($context->getGraph()); if (!$macro) { throw new CompilerException(sprintf("'%s': '%s' macro does not exist", $node->getPath(), $node->getValue())); } if (1 !== count($macro)) { throw new CompilerException(sprintf("'%s': '%s' multiple targets found", $node->getPath(), $node->getValue())); } $node->getParent()->replaceChild($node->getName(), reset($macro)->duplicate($node->getName())); } }
public function execute(Node $node, Context $context) { $path = $node->getPath(); foreach ($this->map as $pattern => $class) { $attributes = Path::match($path, $pattern); if ($attributes !== false) { /* @var $replacement \USync\AST\Drupal\DrupalNodeInterface */ if ($node->isTerminal()) { $replacement = new $class($node->getName(), $node->getValue()); } else { $replacement = new $class($node->getName()); // @todo fix this 2-step terminal check if ($replacement->isTerminal()) { $replacement = new $class($node->getName(), $node->getValue()); } else { $replacement->mergeWith($node); } } $replacement->setAttributes($node->getAttributes() + $attributes); $node->getParent()->replaceChild($node->getName(), $replacement); break; } } }