source: branches/testa-x/php/NorthernCross/ns/PathInfo.php

Last change on this file was 23, checked in by anonymous, 6 years ago

init

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1<?php
2
3namespace ns;
4
5class PathInfo {
6    protected $root;
7    public $hier_hash;
8    protected $root_path;
9
10    function __construct( $root_path ){
11        $this->root_path = $root_path;
12        $this->root = new PathItem( "/" , "/");
13        $this->hier_hash = array();
14        $this->hier_hash["/"] = $this->root;
15    }
16
17    public function register( $path ){
18        $path2 = trim($path);
19        if( strlen($path2) == 0 ){
20            echo "size is 0 - A\n";
21            exit(0);
22        }
23        if( array_key_exists($path2,  $this->hier_hash)){
24            return;
25        }
26        $array = explode("/", $path2);
27        $name = array_pop($array);
28        $item = new PathItem( $name, $path2 , $path2 );
29        $this->hier_hash[$path2] = $item;
30
31        $child_item = $item;
32
33        $dosenot_exist = TRUE;
34        while( count($array) > 0 && $dosenot_exist ){
35            $hier = implode("/" , $array);
36            if( strlen($hier) == 0 ){
37                break;
38            }
39            if (array_key_exists($hier,  $this->hier_hash)){
40                $item = $this->hier_hash[$hier];
41                $dosenot_exist = FALSE;
42            }
43            else {
44                $name = array_pop($array);
45                $item = new PathItem( $name, $hier);
46                $this->hier_hash[$hier] = $item;
47            }
48
49            $child_item->set_parent($item);
50            $child_item = $item;
51        }
52        if( $dosenot_exist ){
53            $child_item->set_parent($this->root);
54        }
55    }
56
57    public function get_pathitem_name( $item ){
58        return $item->get_name();
59    }
60
61    public function pathinfo_list_in_json(){
62        $array = array();
63        foreach( $this->hier_hash as $a => $b ){
64            $names = array_map(array($this, 'get_pathitem_name'), $b->get_children());
65            $array[$a]=$names;
66        }
67        return json_encode($array);
68    }
69
70    public function dump() {
71        #       var_dump($this->hier_hash);
72        foreach( $this->hier_hash as $a => $b ){
73            echo "###########\n";
74            echo "key=" . $a . "\n";
75            echo $b->dump();
76            echo $b->dump_children();
77        }
78    }
79
80    public function dump_root(){
81        $this->root->dump_children();
82    }
83}
84
85?>
Note: See TracBrowser for help on using the repository browser.