Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00017 abstract class NamedTree extends NamedObject
00018 {
00019 private $parent = null;
00020
00024 public function getParent()
00025 {
00026 return $this->parent;
00027 }
00028
00032 public function setParent(NamedTree $parent)
00033 {
00034 Assert::brothers($this, $parent);
00035
00036 $this->parent = $parent;
00037
00038 return $this;
00039 }
00040
00044 public function dropParent()
00045 {
00046 $this->parent = null;
00047
00048 return $this;
00049 }
00050
00054 public function getRoot()
00055 {
00056 $current = $this;
00057 $next = $this;
00058
00059 while ($next) {
00060 $current = $next;
00061 $next = $next->getParent();
00062 }
00063
00064 return $current;
00065 }
00066
00067 public function toString($delimiter = ' :: ')
00068 {
00069 $name = array($this->getName());
00070
00071 $parent = $this;
00072
00073 while ($parent = $parent->getParent())
00074 $name[] = $parent->getName();
00075
00076 $name = array_reverse($name);
00077
00078 return implode($delimiter, $name);
00079 }
00080 }
00081 ?>