NamedTree.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov, Anton E. Lebedevich *
00004  *                                                                          *
00005  *   This program is free software; you can redistribute it and/or modify   *
00006  *   it under the terms of the GNU Lesser General Public License as         *
00007  *   published by the Free Software Foundation; either version 3 of the     *
00008  *   License, or (at your option) any later version.                        *
00009  *                                                                          *
00010  ****************************************************************************/
00011 /* $Id: NamedTree.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4