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