1 | <?php |
||
16 | class Collection implements Countable, Iterator, Serializes { |
||
17 | /** |
||
18 | * Collection elements. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $elements = array(); |
||
23 | |||
24 | /** |
||
25 | * Models registered to the collection. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $model; |
||
30 | |||
31 | /** |
||
32 | * Where Collection is in loop. |
||
33 | * |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $position = 0; |
||
37 | |||
38 | /** |
||
39 | * Collection constructor. |
||
40 | * |
||
41 | * @param array $elements |
||
42 | * @param array $config |
||
43 | */ |
||
44 | 60 | public function __construct( array $elements = array(), array $config = array() ) { |
|
51 | |||
52 | /** |
||
53 | * Adds a new element to the Collection. |
||
54 | * |
||
55 | * @param mixed $element |
||
56 | * |
||
57 | * @throws RuntimeException |
||
58 | */ |
||
59 | 27 | public function add( $element ) { |
|
70 | |||
71 | /** |
||
72 | * Fetches the element at the provided index. |
||
73 | * |
||
74 | * @param int $index |
||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | 12 | public function at( $index ) { |
|
79 | 12 | return isset( $this->elements[ $index ] ) ? $this->elements[ $index ] : null; |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * Return the current element. |
||
84 | * |
||
85 | * @return mixed |
||
86 | */ |
||
87 | 3 | public function current() { |
|
90 | |||
91 | /** |
||
92 | * Move forward to next element. |
||
93 | */ |
||
94 | 3 | public function next() { |
|
97 | |||
98 | /** |
||
99 | * Return the key of the current element. |
||
100 | * |
||
101 | * @return mixed |
||
102 | */ |
||
103 | 3 | public function key() { |
|
106 | |||
107 | /** |
||
108 | * Checks if current position is valid. |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 3 | public function valid() { |
|
115 | |||
116 | /** |
||
117 | * Rewind the Iterator to the first element. |
||
118 | */ |
||
119 | 3 | public function rewind() { |
|
122 | |||
123 | /** |
||
124 | * Count elements of an object. |
||
125 | * |
||
126 | * @return int |
||
127 | */ |
||
128 | 6 | public function count() { |
|
131 | |||
132 | /** |
||
133 | * Parses the Collection config to set its properties. |
||
134 | * |
||
135 | * @param array $config |
||
136 | * |
||
137 | * @throws LogicException |
||
138 | */ |
||
139 | 60 | protected function parse_config( array $config ) { |
|
150 | |||
151 | /** |
||
152 | * {@inheritDoc} |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | public function serialize() { |
||
165 | } |
||
166 |