1: <?php
2:
3: namespace PHPixie\ORM\Relationships\Type\Embeds\Type\Many\Property\Entity;
4:
5: class Items extends \PHPixie\ORM\Relationships\Type\Embeds\Property\Entity
6: implements \ArrayAccess, \Countable
7: {
8:
9: protected function load()
10: {
11: $config = $this->side->config();
12: $this->handler->loadProperty($config, $this->entity);
13: }
14:
15: public function offsetExists($key)
16: {
17: return $this->value()->offsetExists($key);
18: }
19:
20: public function offsetGet($key)
21: {
22: return $this->value()->getByOffset($key);
23: }
24:
25: public function count()
26: {
27: return $this->value()->count();
28: }
29:
30: public function offsetSet($key, $item)
31: {
32: $config = $this->side->config();
33: $this->handler->offsetSet($this->entity, $config, $key, $item);
34: }
35:
36: public function offsetUnset($key)
37: {
38: $config = $this->side->config();
39: $this->handler->offsetUnset($this->entity, $config, $key);
40: }
41:
42: public function create($data = null, $key = null)
43: {
44: $config = $this->side->config();
45: return $this->handler->offsetCreate($this->entity, $config, $key, $data);
46: }
47:
48: public function add($item, $key = null)
49: {
50: $this->offsetSet($key, $item);
51: return $this;
52: }
53:
54: public function remove($items)
55: {
56: $config = $this->side->config();
57: $this->handler->removeItems($this->entity, $config, $items);
58: return $this;
59: }
60:
61: public function removeAll()
62: {
63: $config = $this->side->config();
64: $this->handler->removeAllItems($this->entity, $config);
65: return $this;
66: }
67:
68: public function asData($recursive = false)
69: {
70: $data = array();
71: foreach($this->value() as $entity)
72: $data[] = $entity->asObject($recursive);
73: return $data;
74: }
75: }
76: