1 | <?php |
||
7 | abstract class AbstractObjectContainer extends AbstractGeneratorAware implements \ArrayAccess, \Iterator, \Countable, \JsonSerializable |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | const PROPERTY_NAME = 'name'; |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $objects = array(); |
||
17 | /** |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $offset = 0; |
||
21 | /** |
||
22 | * @param string $offset |
||
23 | * @return bool |
||
24 | */ |
||
25 | 50 | public function offsetExists($offset) |
|
30 | /** |
||
31 | * @param int $offset |
||
32 | * @return mixed |
||
33 | */ |
||
34 | 50 | public function offsetGet($offset) |
|
39 | /** |
||
40 | * @param string $offset |
||
41 | * @param mixed $value |
||
42 | * @return AbstractObjectContainer |
||
43 | */ |
||
44 | 5 | public function offsetSet($offset, $value) |
|
48 | /** |
||
49 | * @param string $offset |
||
50 | * @return AbstractObjectContainer |
||
51 | */ |
||
52 | 5 | public function offsetUnset($offset) |
|
59 | /** |
||
60 | * @return mixed |
||
61 | */ |
||
62 | 535 | public function current() |
|
67 | /** |
||
68 | * @return void |
||
69 | */ |
||
70 | 535 | public function next() |
|
74 | /** |
||
75 | * @return int |
||
76 | */ |
||
77 | 160 | public function key() |
|
81 | /** |
||
82 | * @return bool |
||
83 | */ |
||
84 | 575 | public function valid() |
|
88 | /** |
||
89 | * @return AbstractObjectContainer |
||
90 | */ |
||
91 | 575 | public function rewind() |
|
96 | /** |
||
97 | * @return int |
||
98 | */ |
||
99 | 580 | public function count() |
|
103 | /** |
||
104 | * Must return the object class name that this container is made to contain |
||
105 | * @return string |
||
106 | */ |
||
107 | abstract protected function objectClass(); |
||
108 | /** |
||
109 | * Must return the object class name that this container is made to contain |
||
110 | * @return string |
||
111 | */ |
||
112 | abstract protected function objectProperty(); |
||
113 | /** |
||
114 | * This method is called before the object has been stored |
||
115 | * @throws \InvalidArgumentException |
||
116 | * @param mixed $object |
||
117 | */ |
||
118 | 995 | protected function beforeObjectIsStored($object) |
|
128 | /** |
||
129 | * @param object $object |
||
130 | * @throws \InvalidArgumentException |
||
131 | * @return string |
||
132 | */ |
||
133 | 960 | private function getObjectKey($object) |
|
134 | { |
||
135 | 960 | $get = sprintf('get%s', ucfirst($this->objectProperty())); |
|
136 | 960 | if (!method_exists($object, $get)) { |
|
137 | 5 | throw new \InvalidArgumentException(sprintf('Method "%s" is required in "%s" in order to be stored in "%s"', $get, get_class($object), get_class($this)), __LINE__); |
|
138 | } |
||
139 | 955 | $key = $object->$get(); |
|
140 | 955 | if (!is_scalar($key)) { |
|
141 | throw new \InvalidArgumentException(sprintf('Property "%s" of "%s" must be scalar, "%s" returned', $this->objectProperty(), get_class($object), gettype($key)), __LINE__); |
||
142 | } |
||
143 | 955 | return $key; |
|
144 | } |
||
145 | /** |
||
146 | * @throws \InvalidArgumentException |
||
147 | * @param mixed $object |
||
148 | * @return AbstractObjectContainer |
||
149 | */ |
||
150 | 995 | public function add($object) |
|
156 | /** |
||
157 | * @param string $value |
||
158 | * @return mixed |
||
159 | */ |
||
160 | 800 | public function get($value) |
|
167 | 10 | public function jsonSerialize() |
|
168 | { |
||
171 | } |
||
172 |