php class Branch private storage public function __construct path stor

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
class Branch {
private $storage;
public function __construct($path, &$storage) {
$this->storage = $this->get_create_path($path, $storage);
}
public function get_create_path($path, &$storage){
$parts = explode('.', $path);
$current = $storage;
foreach ( $parts as $p ){
if(!isset($current->$p))
$current->$p = new StdClass;
$current = $current->$p;
}
return $current;
}
public function set($key, $val){
$this->storage->$key = $val;
}
public function get($key){
if(!isset($this->storage->$key)){
return Array();
// throw new Exception('ololo');
}
return $this->storage->$key;
}
}