00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018 abstract class NamedTree extends NamedObject
00019 {
00020 private $parent = null;
00021
00022 public function getParent()
00023 {
00024 return $this->parent;
00025 }
00026
00027 public function setParent(NamedTree $parent)
00028 {
00029 Assert::brothers($this, $parent);
00030
00031 $this->parent = $parent;
00032
00033 return $this;
00034 }
00035
00036 public function dropParent()
00037 {
00038 $this->parent = null;
00039
00040 return $this;
00041 }
00042
00043 public function getRoot()
00044 {
00045 $current = $this;
00046 $next = $this;
00047
00048 while ($next) {
00049 $current = $next;
00050 $next = $next->getParent();
00051 }
00052
00053 return $current;
00054 }
00055
00056 public function toString($delimiter = ' :: ')
00057 {
00058 $name = array($this->getName());
00059
00060 $parent = $this;
00061
00062 while ($parent = $parent->getParent())
00063 $name[] = $parent->getName();
00064
00065 $name = array_reverse($name);
00066
00067 return implode($delimiter, $name);
00068 }
00069 }
00070 ?>