public function execute(Node $node, Context $context)
 {
     if ($node instanceof ExpressionNode) {
         // FIXME This is very disturbing to evaluate this way, but I do
         // not have much choices for now
         // @todo Later use Symfony Expression Language component instead
         $node->evaluateExpression();
     }
 }
 public function execute(Node $node, Context $context)
 {
     foreach (array('dirty', 'merge') as $key) {
         if ($node->hasChild($key)) {
             $dirty = $node->getChild($key);
             if ($dirty instanceof ValueNode) {
                 $node->setAttribute($key, (bool) $dirty->getValue());
                 $node->removeChild($key);
             }
         }
     }
 }
Exemplo n.º 3
0
 public function getPosition()
 {
     if (!$this->parent) {
         return 0;
     }
     return $this->parent->getChildPosition($this);
 }
 /**
  * parse() method internal recursion
  *
  * @param Node $parent
  * @param string $name
  * @param mixed $value
  */
 protected function _parse(Node $parent, $name, $value = null)
 {
     switch (gettype($value)) {
         case "array":
         case "object":
             $node = new Node($name, $value);
             break;
         case "boolean":
             $node = new BooleanValueNode($name, $value);
             break;
         case "NULL":
             $node = new NullValueNode($name, $value);
             break;
         case "string":
             if ('@=' === substr($value, 0, 2)) {
                 $node = new ExpressionNode($name, $value);
             } else {
                 if ('@' === substr($value, 0, 1)) {
                     $node = new MacroReferenceNode($name, $value);
                 } else {
                     $node = new StringNode($name, $value);
                 }
             }
             break;
         case "integer":
         case "double":
         case "resource":
         default:
             $node = new ValueNode($name, $value);
             break;
     }
     if (null === $value || 'delete' === $value) {
         $node->setAttribute('delete', true);
     }
     $parent->addChild($node);
     if (!$node->isTerminal() && is_array($value) || $value instanceof \Traversable) {
         foreach ($value as $key => $sValue) {
             $this->_parse($node, $key, $sValue);
         }
     }
 }
Exemplo n.º 5
0
 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;
         }
     }
 }
Exemplo n.º 7
0
 public function execute(Node $node, Context $context)
 {
     $sorted = array();
     $orphans = array();
     $path = $node->getPath();
     foreach ($node->getChildren() as $key => $child) {
         if ($child->hasChild('inherit')) {
             $parent = $child->getChild('inherit')->getValue();
             if (!is_string($parent)) {
                 $context->logCritical(sprintf("%s: %s: malformed inherit directive", $path, $key));
             }
             if (!$node->hasChild($parent)) {
                 $context->logCritical(sprintf("%s: %s: cannot inherit from non existing: %s", $path, $key, $parent));
             }
             if ($key === $parent) {
                 $context->logCritical(sprintf("%s: %s: cannot inherit from itself", $path, $key));
             }
             $child->removeChild('inherit');
             $orphans[$key] = $parent;
         } else {
             $sorted[$key] = array();
         }
     }
     while (!empty($orphans)) {
         $count = count($orphans);
         foreach ($orphans as $key => $parent) {
             if (isset($sorted[$parent])) {
                 $sorted[$parent][] = $key;
                 $sorted[$key] = array();
                 unset($orphans[$key]);
             }
         }
         if (count($orphans) === $count) {
             $context->logCritical(sprintf("%s: circular dependency detected", $path));
         }
     }
     foreach (array_filter($sorted) as $parent => $children) {
         foreach ($children as $name) {
             $node->getChild($name)->setAttribute('inherits', $node->getChild($parent)->getPath());
         }
     }
 }
Exemplo n.º 8
0
 /**
  * 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);
 }