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; } } }
/** * Execute traversal of the graph using the given processors * * @param \USync\AST\Node $node */ protected function executeBottomTop(Node $node, Context $context) { if (!$node->isTerminal()) { foreach ($node->getChildren() as $child) { $this->executeBottomTop($child, $context); } } $this->executeProcessorsOnNode($node, $context); }