/**
  * @param Node $node
  * @param Context $context
  * @throws TypeNotSupportedException
  * @return Node the resolved node
  */
 public function resolve(Node $node, Context $context)
 {
     if (!$node->hasType()) {
         $node = $this->baseResolver->resolve($node, $context);
         foreach ($node->getChildNodes() as $childNodes) {
             $this->resolve($childNodes, $context);
         }
     }
     return $node;
 }
 /**
  * @param Node $node
  * @param Context $context
  * @throws TypeNotSupportedException
  * @return Node the resolved node
  */
 public function resolve(Node $node, Context $context)
 {
     if (!$node->hasType()) {
         foreach ($this->resolvers as $resolver) {
             try {
                 return $resolver->resolve($node, $context);
             } catch (TypeNotSupportedException $ex) {
                 // No problem, just try the next one
             }
         }
         throw new TypeNotSupportedException();
     }
     return $node;
 }
Esempio n. 3
0
 /**
  * @param Node $node
  * @return array
  */
 private function getReferencePathData($node)
 {
     $frontier = [[$node->getId()]];
     $result = [];
     $rootId = $this->nodes[0]->getId();
     while (count($frontier) > 0) {
         $newFrontier = [];
         foreach ($frontier as $path) {
             $base = $path[0];
             if ($base === $rootId) {
                 $result[] = $path;
             } else {
                 $parentRefs = $this->getReferences()[$base];
                 foreach (array_keys($parentRefs) as $parentId) {
                     if (!in_array($parentId, $path)) {
                         $newFrontier[] = array_merge([$parentId], $path);
                     }
                 }
             }
         }
         $frontier = $newFrontier;
     }
     return $result;
 }
 /**
  * @param Node $node
  * @param Context $context
  * @throws TypeNotSupportedException
  * @return Node the resolved node
  */
 public function resolve(Node $node, Context $context)
 {
     if (!$node->hasType()) {
         $data = $node->getData();
         if ($this->supports($data)) {
             $node->setType($this->getType());
             foreach ($this->getProperties($data) as $key => $value) {
                 $childNode = $context->getNodeForData($value);
                 $node->addChildNode($key, $childNode);
             }
         } else {
             throw new TypeNotSupportedException();
         }
     }
     return $node;
 }