1 | <?php |
||
23 | class Indexed implements CollectionInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var EventInterface[][] |
||
27 | */ |
||
28 | protected $events; |
||
29 | |||
30 | /** |
||
31 | * Event count. |
||
32 | * |
||
33 | * @var int |
||
34 | */ |
||
35 | protected $count = 0; |
||
36 | |||
37 | /** |
||
38 | * The function used to index events. |
||
39 | * Takes a \DateTime in parameter and must return an array index for this value. |
||
40 | * |
||
41 | * By default : |
||
42 | * ```php |
||
43 | * function(\DateTime $dateTime) { |
||
44 | * return $dateTime->format('Y-m-d'); |
||
45 | * } |
||
46 | * ``` |
||
47 | * |
||
48 | * @var callable |
||
49 | */ |
||
50 | protected $indexFunction; |
||
51 | |||
52 | /** |
||
53 | * @param array<EventInterface> $events |
||
54 | * @param callable|null $callable |
||
55 | */ |
||
56 | public function __construct(array $events = array(), $callable = null) |
||
70 | |||
71 | /** |
||
72 | * Adds an event to the collection. |
||
73 | * |
||
74 | * @param EventInterface $event |
||
75 | */ |
||
76 | public function add(EventInterface $event) |
||
87 | |||
88 | /** |
||
89 | * Removes an event from the collection. |
||
90 | * |
||
91 | * @param EventInterface $event |
||
92 | */ |
||
93 | public function remove(EventInterface $event) |
||
105 | |||
106 | /** |
||
107 | * Returns if we have events for the given index. |
||
108 | * |
||
109 | * @param mixed $index |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function has($index) |
||
117 | |||
118 | /** |
||
119 | * returns events. |
||
120 | * |
||
121 | * @param mixed $index |
||
122 | * |
||
123 | * @return EventInterface[] |
||
124 | */ |
||
125 | public function find($index) |
||
136 | |||
137 | /** |
||
138 | * Returns a flattened array of all events. |
||
139 | * |
||
140 | * @return EventInterface[] |
||
141 | */ |
||
142 | public function all() |
||
152 | |||
153 | /** |
||
154 | * Computes event index. |
||
155 | * |
||
156 | * @param EventInterface|\DateTime $toCompute |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | protected function computeIndex($toCompute) |
||
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | public function count() |
||
177 | } |
||
178 |