1 | <?php |
||
5 | abstract class AbstractCollection implements \IteratorAggregate, \Countable |
||
6 | { |
||
7 | /** |
||
8 | * @var The array where data are stored internally |
||
9 | */ |
||
10 | protected $data = []; |
||
11 | |||
12 | /** |
||
13 | * Check if an object is present in the collection. |
||
14 | * The check will be done by `===` |
||
15 | * @param $objectToFind The object you want to check if it's already present. |
||
16 | * @return bool True if present else false |
||
17 | */ |
||
18 | 3 | public function contains($objectToFind) : bool |
|
19 | { |
||
20 | 3 | foreach ($this as $elem) { |
|
21 | 3 | if ($elem === $objectToFind) { |
|
22 | 3 | return true; |
|
23 | } |
||
24 | } |
||
25 | 3 | return false; |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * Count elements of an object |
||
30 | * |
||
31 | * @link http://php.net/manual/en/countable.count.php |
||
32 | * @return int The custom count as an integer. |
||
33 | * </p> |
||
34 | * <p> |
||
35 | * The return value is cast to an integer. |
||
36 | * @since 5.1.0 |
||
37 | */ |
||
38 | 2 | public function count() |
|
42 | |||
43 | |||
44 | /** |
||
45 | * Retrieve an external iterator |
||
46 | * |
||
47 | * @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
||
48 | * @return \Traversable An instance of an object implementing <b>Iterator</b> or |
||
49 | * <b>Traversable</b> |
||
50 | * @since 5.0.0 |
||
51 | */ |
||
52 | 11 | public function getIterator() |
|
56 | } |
||
57 |