MaterializedPath.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace Gedmo\Tree\Traits;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. /**
  6. * MaterializedPath Trait
  7. *
  8. * @author Steffen Roßkamp <steffen.rosskamp@gimmickmedia.de>
  9. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  10. */
  11. trait MaterializedPath
  12. {
  13. /**
  14. * @var string
  15. */
  16. protected $path;
  17. /**
  18. * @var self
  19. */
  20. protected $parent;
  21. /**
  22. * @var integer
  23. */
  24. protected $level;
  25. /**
  26. * @var Collection|self[]
  27. */
  28. protected $children;
  29. /**
  30. * @var string
  31. */
  32. protected $hash;
  33. /**
  34. * @param self $parent
  35. *
  36. * @return self
  37. */
  38. public function setParent(self $parent = null)
  39. {
  40. $this->parent = $parent;
  41. return $this;
  42. }
  43. /**
  44. * @return self
  45. */
  46. public function getParent()
  47. {
  48. return $this->parent;
  49. }
  50. /**
  51. * @param string $path
  52. *
  53. * @return self
  54. */
  55. public function setPath($path)
  56. {
  57. $this->path = $path;
  58. return $this;
  59. }
  60. /**
  61. * @return string
  62. */
  63. public function getPath()
  64. {
  65. return $this->path;
  66. }
  67. /**
  68. * @return integer
  69. */
  70. public function getLevel()
  71. {
  72. return $this->level;
  73. }
  74. /**
  75. * @param string $hash
  76. *
  77. * @return self
  78. */
  79. public function setHash($hash)
  80. {
  81. $this->hash = $hash;
  82. return $this;
  83. }
  84. /**
  85. * @return string
  86. */
  87. public function getHash()
  88. {
  89. return $this->hash;
  90. }
  91. /**
  92. * @param Collection|self[] $children
  93. *
  94. * @return self
  95. */
  96. public function setChildren($children)
  97. {
  98. $this->children = $children;
  99. return $this;
  100. }
  101. /**
  102. * @return Collection|self[]
  103. */
  104. public function getChildren()
  105. {
  106. return $this->children = $this->children ?: new ArrayCollection();
  107. }
  108. }