Guest User

Untitled

a guest
Jul 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <?php
  2.  
  3. interface NodeInfo
  4. {
  5. public function getLeftValue();
  6. public function setLeftValue($value);
  7.  
  8. public function getRightValue();
  9. public function setRightValue($value);
  10.  
  11. public function getLevel();
  12. public function setLevel($value);
  13.  
  14. public function getRootValue();
  15. public function setRootValue($value);
  16. }
  17.  
  18.  
  19. interface Node extends NodeInfo
  20. {
  21. public function __construct($entity);
  22.  
  23. public function hasPrevSibling();
  24. public function hasNextSibling();
  25. public function hasChildren();
  26. public function hasParent();
  27. public function isRoot();
  28.  
  29. public function unwrap();
  30.  
  31. public function getPrevSibling();
  32. public function getNextSibling();
  33. public function getChildren();
  34. public function getParent();
  35. public function getFirstChild();
  36. public function getLastChild();
  37.  
  38. public function delete();
  39.  
  40. public function addChild(Node $node);
  41.  
  42. public function insertAsLastChildOf(Node $node);
  43. public function insertAsFirstChildOf(Node $node);
  44. public function insertAsNextSiblingOf(Node $node);
  45. public function insertAsPrevSiblingOf(Node $node);
  46. public function moveAsLastChildOf(Node $node);
  47. public function moveAsFirstChildOf(Node $node);
  48. public function moveAsNextSiblingOf(Node $node);
  49. public function moveAsPrevSiblingOf(Node $node);
  50. }
  51.  
  52.  
  53. class AbstractDecorator
  54. {
  55. protected $entity;
  56.  
  57. public function __construct($entity)
  58. {
  59. $this->entity = $entity;
  60.  
  61. $this->_initMetadata();
  62. }
  63.  
  64. public function unwrap()
  65. {
  66. return $this->entity;
  67. }
  68.  
  69. // ...
  70. }
  71.  
  72.  
  73. class NestedSetDecorator extends AbstractDecorator implements Node
  74. {
  75. public function hasChildren()
  76. {
  77. $rgtValue = $this->_getEntityValue('rightFieldName');
  78. $lftValue = $this->_getEntityValue('leftFieldName');
  79.  
  80. return ($rgtValue - $lftValue) > 1;
  81. }
  82.  
  83. // ...
  84. }
  85.  
  86.  
  87. class AdjacencyListDecorator extends AbstractDecorator implements Node
  88. {
  89. // ...
  90. }
  91.  
  92.  
  93. class MaterializedPathDecorator extends AbstractDecorator implements Node
  94. {
  95. // ...
  96. }
  97.  
  98.  
  99. class HierarchicalManager
  100. {
  101. private $em;
  102.  
  103. public function __construct(EntityManager $em)
  104. {
  105. $this->em = $em;
  106. }
  107.  
  108. public function getNode($entity)
  109. {
  110. return new NestedSetDecorator($entity);
  111. }
  112.  
  113. public function createRoot($entity)
  114. {
  115. // ...
  116. }
  117.  
  118. // ...
  119. }
Add Comment
Please, Sign In to add comment