/** * Set all children (outgoing) of the node * * This disconnects all current children of the node, and then connects * the node to the given array (turned RestrictedSet). * * @see connectIncoming() * * @param array (of Falcraft\Data\Types\Resource\VertexInterface) of new parents * */ public function setOutgoing(array $outgoing = array()) { $outgoing = RestrictedSet::build($outgoing, $this->restrictions, array('strict' => true)); Set::map(array($this, 'disconnectOutgoing'), $this->outgoing); foreach ($this->outgoing->iterate() as $vertex) { $vertex->disconnectIncoming($this); } Set::map(array($this, 'connectOutgoing'), $outgoing); foreach ($outgoing->iterate() as $vertex) { $vertex->connectIncoming($this); } }
} catch (\InvalidArgumentException $e) { $failure = true; } if ($failure) { echo "Failure!\n"; } else { echo "Success...\n"; } echo "Instantiating Correct Ordered Node -> "; $testCorrectRestrictions = $testCorrectRestrictedSet1 = null; $testCorrectRestrictedSet2 = $testCorrectOrderedNode = null; $success = true; try { $testCorrectRestrictions = new Types\Restrictions(array(Types\Type::TYPED_OBJECT), array('Falcraft\\Data\\Types\\Resource\\VertexInterface')); $testCorrectRestrictedSet1 = Types\RestrictedSet::build(array(), $testCorrectRestrictions); $testCorrectRestrictedSet2 = Types\RestrictedSet::build(array(), $testCorrectRestrictions); $testCorrectOrderedNode = new Types\OrderedNode($testCorrectRestrictedSet1, array(), $testCorrectRestrictedSet2); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } echo "Retrieving Restrictions -> \n\n"; var_dump($testCorrectOrderedNode->getRestrictions()); echo "\n\n"; echo "Creating Vertices -- \n"; echo "UnorderedNodes: parentNode, rightNode, middleNode, leftNode, offsideNode, auxiliaryNode\n"; $success = true;
/** * Clear all the vertices out of the list * */ public function clear() { $this->edges = RestrictedSet::build(array(), $this->restrictions, array('strict' => true)); $newEdge = new OrderedEdge(); $this->edges->addReference($newEdge); }
/** * OrderedNode Class Constructor * * It takes two RestrictedSets, whose restrictions have to match the * OrderedNode restrictions (VertexInterface). In this vertex model * (ordered node) incoming connections are parents, outgoing connections * are children, and mutual connections are siblings. * * Children are a special matter, they're made up a VertexList. * A VertexList is an ordered list of Vertices (held together * by a double linked list of edges) The vertexlist takes care of the * children's mutual connections (I know, bad coupling). To do * vertexlist operations use getVertexList() * * This initializes the restrictions member for the interface * VertexInterface (supported in Falcraft\Data\Types\Restrictions 1.3) * * @param Falcraft\Data\Types\RestrictedSet $parents * The initial parent vertices * @param array $children * The initial children vertices in reference * @param Falcraft\Data\Types\RestrictedSet $siblings * The initial sibling vertices * * @throws TypesException\InvalidArgumentException * If a given RestrictedSet has non-matching restrictions * */ public function __construct(RestrictedSet $parents = null, array $children = array(), RestrictedSet $siblings = null, array $options = array()) { parent::__construct(null, null, null, $options); // Initialize restrictions, anything that is an instanceof (implements) VertexInterface) $this->restrictions = new Restrictions(array(Type::TYPED_OBJECT), array('Falcraft\\Data\\Types\\Resource\\VertexInterface'), array('autoload' => true)); // Map the parameters to the AbstractVertex lingo $params = array('incoming' => 'parents', 'mutual' => 'siblings'); // Cycle through parameters, replacing 'incoming' with 'parents' etc. // This whole mixup is done so that people won't be confused about where // to put parents, children, and siblings. (incoming, outgoing, mutual) foreach ($params as $key => $param) { if (is_null(${$param})) { $this->{$param} = RestrictedSet::build(array(), $this->restrictions, array('strict' => true)); // Make sure the restrictions on the RestrictedSet match with our own restrictions } else { if (Restrictions::compare($this->restrictions, ${$param}->getRestrictions())) { $this->{$key} = ${$param}; } else { throw new TypesException\InvalidArgumentException('OrderedNode->__construct: Improper RestrictedSet At ' . 'Constructor: ' . $param); } } } // Children are a special matter in this class $this->outgoing = new VertexList($children); }