| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | namespace ns; |
|---|
| 4 | |
|---|
| 5 | class PathItem { |
|---|
| 6 | public $name = NULL; |
|---|
| 7 | public $hier = NULL; |
|---|
| 8 | public $id = NULL; |
|---|
| 9 | protected $parent = NULL; |
|---|
| 10 | protected $children = array(); |
|---|
| 11 | protected $file_path = NULL; |
|---|
| 12 | static $inst_count = 0; |
|---|
| 13 | |
|---|
| 14 | function __construct($name, $hier, $file_path = NULL , $parent = NULL){ |
|---|
| 15 | $this->name = $name; |
|---|
| 16 | $this->hier = $hier; |
|---|
| 17 | $this->file_path = $file_path; |
|---|
| 18 | $this->parent = $parent; |
|---|
| 19 | $this->id = PathItem::$inst_count++; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | public function get_name(){ |
|---|
| 23 | return $this->name; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | public function get_children(){ |
|---|
| 27 | return $this->children; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | public function set_parent($parent){ |
|---|
| 31 | if( $this->parent == NULL ){ |
|---|
| 32 | $this->parent = $parent; |
|---|
| 33 | $this->parent->add_child($this); |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | public function add_child($child){ |
|---|
| 38 | if( !array_search($child, $this->children, TRUE) ){ |
|---|
| 39 | array_push($this->children, $child); |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | public function dump(){ |
|---|
| 44 | echo "id=" . $this->id . "\n"; |
|---|
| 45 | echo "name=" . $this->name . "\n"; |
|---|
| 46 | echo "hier=" . $this->hier . "\n"; |
|---|
| 47 | echo "filepath=" . $this->file_path . "\n"; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public function dump_children(){ |
|---|
| 51 | foreach($this->children as $item){ |
|---|
| 52 | echo "child id=" . $item->id . "\n"; |
|---|
| 53 | echo "child name=" . $item->name . "\n"; |
|---|
| 54 | echo "child hier=" . $item->hier . "\n"; |
|---|
| 55 | } |
|---|
| 56 | echo "\n"; |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | ?> |
|---|