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 | * The parent loop, if any |
||
23 | * |
||
24 | * @var Loop |
||
25 | */ |
||
26 | protected $parentLoop; |
||
27 | |||
28 | protected $loopFactory; |
||
29 | |||
30 | /** |
||
31 | * Sets the parent loop |
||
32 | * |
||
33 | * @param Loop $parentLoop |
||
34 | * {@inheritdocs} |
||
35 | */ |
||
36 | public function setParentLoop(Loop $parentLoop) |
||
41 | |||
42 | /** |
||
43 | * Returns the full loop stack of the LoopFactory |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function getLoopStack() |
||
51 | |||
52 | /** |
||
53 | * Resets the loop stack of the LoopFactory |
||
54 | */ |
||
55 | public function resetLoopStack() |
||
59 | |||
60 | /** |
||
61 | * Instantiates the class |
||
62 | * |
||
63 | * @param LoopFactory $loopFactory |
||
64 | * @param array $items The array that's being iterated |
||
65 | */ |
||
66 | 6 | public function __construct(LoopFactory $loopFactory, $items) |
|
71 | |||
72 | /** |
||
73 | * Sets the array to monitor |
||
74 | * |
||
75 | * @param array $items The array that's being iterated |
||
76 | */ |
||
77 | 6 | public function setItems($items) |
|
93 | |||
94 | 6 | public function getItems() |
|
98 | |||
99 | /** |
||
100 | * Magic method to access the loop data properties |
||
101 | * |
||
102 | * @param $key |
||
103 | * |
||
104 | * @return mixed |
||
105 | */ |
||
106 | 6 | public function __get($key) |
|
110 | |||
111 | /** |
||
112 | * To be called first in a loop before anything else |
||
113 | */ |
||
114 | 6 | public function before() |
|
122 | |||
123 | /** |
||
124 | * To be called last in a loop after everything else |
||
125 | */ |
||
126 | 6 | public function after() |
|
133 | } |
||
134 |