| 1 | <?php |
||
| 5 | class Loop |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * The array that is being iterated |
||
| 9 | * |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | protected $items = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The data for the current $loop item |
||
| 16 | * |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected $data; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Instantiates the class |
||
| 23 | * |
||
| 24 | * @param array $items The array that's being iterated |
||
| 25 | */ |
||
| 26 | 15 | public function __construct($items) |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Sets the array to monitor |
||
| 34 | * |
||
| 35 | * @param array $items The array that's being iterated |
||
| 36 | */ |
||
| 37 | 15 | protected function init($items) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Sets the parent loop |
||
| 49 | * |
||
| 50 | * @param Loop $parentLoop |
||
| 51 | */ |
||
| 52 | 3 | public function setParentLoop(Loop $parentLoop) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Return array that must be iterated. |
||
| 59 | * |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | 15 | public function getItems() |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Magic method to access the loop data properties |
||
| 69 | * |
||
| 70 | * @param $key |
||
| 71 | * |
||
| 72 | * @return mixed |
||
| 73 | */ |
||
| 74 | 15 | public function __get($key) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * To be called first in a loop before anything else |
||
| 81 | */ |
||
| 82 | 15 | public function loop() |
|
| 95 | } |
||
| 96 |