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