/** * Build the missing items in AST ommiting the last segment * * @param \USync\AST\NodeInterface $ast * @param \USync\AST\Path $path * * @return \USync\AST\NodeInterface * The last parent */ protected function fixTree(NodeInterface $ast, $path) { $segments = $path->getSegments(); array_pop($segments); $node = $ast; foreach ($segments as $key) { if ($node->hasChild($key)) { $node = $node->getChild($key); } else { $child = new Node($key); $node->addChild($child); $node = $child; } } return $node; }
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; } } }