Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface NodeInfo
- {
- public function getLeftValue();
- public function setLeftValue($value);
- public function getRightValue();
- public function setRightValue($value);
- public function getLevel();
- public function setLevel($value);
- public function getRootValue();
- public function setRootValue($value);
- }
- interface Node extends NodeInfo
- {
- public function __construct($entity);
- public function hasPrevSibling();
- public function hasNextSibling();
- public function hasChildren();
- public function hasParent();
- public function isRoot();
- public function unwrap();
- public function getPrevSibling();
- public function getNextSibling();
- public function getChildren();
- public function getParent();
- public function getFirstChild();
- public function getLastChild();
- public function delete();
- public function addChild(Node $node);
- public function insertAsLastChildOf(Node $node);
- public function insertAsFirstChildOf(Node $node);
- public function insertAsNextSiblingOf(Node $node);
- public function insertAsPrevSiblingOf(Node $node);
- public function moveAsLastChildOf(Node $node);
- public function moveAsFirstChildOf(Node $node);
- public function moveAsNextSiblingOf(Node $node);
- public function moveAsPrevSiblingOf(Node $node);
- }
- class AbstractDecorator
- {
- protected $entity;
- public function __construct($entity)
- {
- $this->entity = $entity;
- $this->_initMetadata();
- }
- public function unwrap()
- {
- return $this->entity;
- }
- // ...
- }
- class NestedSetDecorator extends AbstractDecorator implements Node
- {
- public function hasChildren()
- {
- $rgtValue = $this->_getEntityValue('rightFieldName');
- $lftValue = $this->_getEntityValue('leftFieldName');
- return ($rgtValue - $lftValue) > 1;
- }
- // ...
- }
- class AdjacencyListDecorator extends AbstractDecorator implements Node
- {
- // ...
- }
- class MaterializedPathDecorator extends AbstractDecorator implements Node
- {
- // ...
- }
- class HierarchicalManager
- {
- private $em;
- public function __construct(EntityManager $em)
- {
- $this->em = $em;
- }
- public function getNode($entity)
- {
- return new NestedSetDecorator($entity);
- }
- public function createRoot($entity)
- {
- // ...
- }
- // ...
- }
Add Comment
Please, Sign In to add comment