Total Complexity | 9 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
3 | class MultiPk implements \ArrayAccess { |
||
4 | private $parent; |
||
5 | private $primaryKey; |
||
6 | private $lookup; |
||
7 | private $mapper; |
||
8 | |||
9 | public function __construct(Maphper $mapper, $lookup, array $primaryKey, MultiPk $parent = null) { |
||
10 | $this->parent = $parent; |
||
11 | $this->primaryKey = $primaryKey; |
||
12 | $this->lookup = $lookup; |
||
13 | $depth = $this->getDepth(); |
||
14 | $this->mapper = $mapper->filter([$primaryKey[$depth] => $lookup]); |
||
|
|||
15 | } |
||
16 | |||
17 | private function getDepth() { |
||
18 | $depth = 0; |
||
19 | $obj = $this; |
||
20 | while ($obj->parent != null) { |
||
21 | $depth++; |
||
22 | $obj = $obj->parent; |
||
23 | } |
||
24 | return $depth; |
||
25 | } |
||
26 | |||
27 | public function offsetGet($key) { |
||
31 | } |
||
32 | |||
33 | public function offsetSet($key, $value) { |
||
34 | $keys = $this->primaryKey; |
||
35 | $obj = $this; |
||
36 | $key1 = array_pop($keys); |
||
37 | $value->$key1 = $key; |
||
38 | |||
39 | while ($key = array_pop($keys)) { |
||
40 | $value->$key = $obj->lookup; |
||
41 | $obj = $obj->parent; |
||
42 | } |
||
43 | $this->mapper[] = $value; |
||
44 | } |
||
45 | |||
46 | public function offsetUnset($key) { |
||
49 | } |
||
50 | |||
51 | public function offsetExists($key) { |
||
53 | } |
||
54 | } |
||
55 |