/** * 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); } }
/** * Remove this observer from all publishers * */ public function unlink() { Types\RestrictedSet::mapInternal('detachListener', array($this), $this->subject); }
} 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); }
/** * Announce our state to all our listeners * */ public function announce() { Types\RestrictedSet::mapInternal('notify', array(&$this, &$this->state), $this->observers); }
/** * Calls an internal member function of a set member with arguments * * Like map, only it calls a particular method on the given object, * this is possible because the set can be guaranteed to hold only * certain objects. Do not attempt on a mixed set. * * @param string $method The method name to call * @param array $args The arguments to pass to the method * @param Falcraft\Data\Types\Set $S The set to act on * */ public static function mapInternal($method, $args, RestrictedSet $S) { foreach ($S->iterate() as $object) { if (method_exists($object, $method)) { call_user_func_array(array($object, $method), $args); } } }
/** * Detach conduit from everything * * NOTE: you only detach yourself from the aggregate */ public function unlink() { $listeners = $this->conduit->getValues(); Types\RestrictedSet::mapInternal('detach', array($this), $listeners); $this->publishers->detachListener($this); }
$hash2 = $testRestrictedSet->hash(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success! ({$hash}, {$hash2})\n"; } else { echo "Failure..."; } class testClass { public $publicProp; } $obj = new testClass(); $identity = null; $testRestrictedSetReference = new Types\RestrictedSet(array(), new Types\Restrictions(array(Type::TYPED_OBJECT), array('testClass')), array('strict' => true, 'unique' => true)); echo "Add Reference -> \n"; try { $obj->publicProp = 2; $identity = $testRestrictedSetReference->addReference($obj); $obj->publicProp = 3; echo "\nSet Internals --\n\n"; var_dump($testRestrictedSetReference->getArray()); echo "\n"; } catch (\Exception $e) { echo "EXCEPTION CAUGHT\n"; } echo "Retrieve Reference -> "; unset($obj); try { $obj = $testRestrictedSetReference->retrieveReference($identity);
/** * 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); }