Exemplo n.º 1
0
 public function __construct(EdgeSchema $edge_schema, Node $node, $direction = self::ALL, array $properties = null)
 {
     if (!$node->hasId()) {
         throw new \InvalidArgumentException('Cannot get an edge collection from a node with no ID.');
     }
     $node_schema = $node->getSchema();
     switch ($direction) {
         case self::OUT:
             if (!$edge_schema->permitsStartNode($node_schema)) {
                 throw new Exceptions\SchemaException('The schema for edges of type "' . $edge_schema->getName() . '" does not permit edges from nodes of type "' . $node_schema->getName() . '".');
             }
             break;
         case self::IN:
             if (!$edge_schema->permitsEndNode($node_schema)) {
                 throw new Exceptions\SchemaException('The schema for edges of type "' . $edge_schema->getName() . '" does not permit edges to nodes of type "' . $node_schema->getName() . '".');
             }
             break;
         case self::ALL:
             if (!$edge_schema->permitsEndNode($node_schema) and !$edge_schema->permitsStartNode($node_schema)) {
                 throw new Exceptions\SchemaException('The schema for edges of type "' . $edge_schema->getName() . '" does not permit edges to or from nodes of type "' . $node_schema->getName() . '".');
             }
             break;
         default:
             throw new \RuntimeException('Invalid direction: "' . $direction . '".');
     }
     $this->node = $node;
     $this->direction = $direction;
     parent::__construct($edge_schema, $properties);
 }
Exemplo n.º 2
0
 public function get($id)
 {
     $node = new Node($this, $id);
     // Preload data before returning.
     // NotFoundException will be thrown if:
     //  - the node does not exist
     // SchemaException will be thrown if:
     //  - there's a mismatch between the requested node and the given schema
     $node->fetch();
     return $node;
 }
Exemplo n.º 3
0
 public function setRelationship(Node $start_node, Node $end_node)
 {
     if ($start_node->hasId() and $start_node->getId() === $end_node->getId()) {
         throw new Exceptions\SchemaException('A node may not have an edge to itself.');
     }
     if (!$this->schema->permits($start_node->getSchema(), $end_node->getSchema())) {
         throw new Exceptions\SchemaException('Relationship between ' . $start_node->getSchema()->getName() . ' and ' . $end_node->getSchema()->getName() . ' forbidden by schema.');
     }
     $this->end_node = $end_node;
     $this->start_node = $start_node;
 }
Exemplo n.º 4
0
 public function process(Node $node)
 {
     $node->index();
 }