1 | <?php |
||
16 | class JailedDocument implements \ArrayAccess, \IteratorAggregate |
||
17 | { |
||
18 | /** |
||
19 | * @var string[] |
||
20 | */ |
||
21 | private $whiteListFunctions; |
||
22 | |||
23 | /** |
||
24 | * @var string[] |
||
25 | */ |
||
26 | private $jailedFunctions; |
||
27 | |||
28 | /** |
||
29 | * @var JailableDocument |
||
30 | */ |
||
31 | private $object; |
||
32 | |||
33 | /** |
||
34 | * JailObject constructor. |
||
35 | * |
||
36 | * @param JailableDocument $object The object that will be jailed |
||
37 | * @param array $whiteListFunctions A list of function names that can be called |
||
38 | * @param array $jailedFunctions |
||
39 | */ |
||
40 | 55 | public function __construct(&$object, array $whiteListFunctions, array $jailedFunctions = array()) |
|
41 | { |
||
42 | 55 | if (!($object instanceof JailableDocument) && |
|
43 | 55 | !($object instanceof \ArrayAccess) && |
|
44 | 55 | !($object instanceof \IteratorAggregate)) |
|
45 | { |
||
46 | throw new \InvalidArgumentException('Must implement the ArrayAccess and Jailable interfaces'); |
||
47 | } |
||
48 | |||
49 | 55 | $this->object = &$object; |
|
50 | 55 | $this->whiteListFunctions = $whiteListFunctions; |
|
51 | 55 | $this->jailedFunctions = $jailedFunctions; |
|
52 | 55 | } |
|
53 | |||
54 | 11 | public function __call($name, $arguments) |
|
76 | |||
77 | public function coreInstanceOf($class) |
||
78 | { |
||
79 | return is_subclass_of($this->object, $class); |
||
80 | } |
||
81 | |||
82 | // |
||
83 | // ArrayAccess Implementation |
||
84 | // |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 22 | public function offsetExists($offset) |
|
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | 32 | public function offsetGet($offset) |
|
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function offsetSet($offset, $value) |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function offsetUnset($offset) |
||
117 | |||
118 | // |
||
119 | // IteratorAggregate implementation |
||
120 | // |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | 19 | public function getIterator() |
|
129 | } |
||
130 |