Esempio 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);
 }