コード例 #1
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());
         }
     }
 }
コード例 #2
0
ファイル: Visitor.php プロジェクト: makinacorpus/drupal-usync
 /**
  * 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);
 }