1 | <?php |
||
21 | class RuleIterator implements Iterator |
||
22 | { |
||
23 | /** |
||
24 | * |
||
25 | * The rules to iterate through. |
||
26 | * |
||
27 | * @var array |
||
28 | * |
||
29 | */ |
||
30 | protected $rules = []; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * Constructor. |
||
35 | * |
||
36 | * @param array $rules The rules to iterate through. |
||
37 | * |
||
38 | */ |
||
39 | 8 | public function __construct(array $rules = []) |
|
43 | |||
44 | /** |
||
45 | * |
||
46 | * Sets the rules to iterate through. |
||
47 | * |
||
48 | * @param array $rules The rules to iterate through. |
||
49 | * |
||
50 | */ |
||
51 | 8 | public function set(array $rules) |
|
52 | { |
||
53 | 8 | $this->rules = []; |
|
54 | 8 | foreach ($rules as $rule) { |
|
55 | 8 | $this->append($rule); |
|
56 | 8 | } |
|
57 | 8 | } |
|
58 | |||
59 | /** |
||
60 | * |
||
61 | * Appends a rule to iterate through. |
||
62 | * |
||
63 | * @param callable $rule The rule to iterate through. |
||
64 | * |
||
65 | */ |
||
66 | 8 | public function append(callable $rule) |
|
70 | |||
71 | /** |
||
72 | * |
||
73 | * Prepends a rule to iterate through. |
||
74 | * |
||
75 | * @param callable $rule The rule to iterate through. |
||
76 | * |
||
77 | */ |
||
78 | 1 | public function prepend(callable $rule) |
|
82 | |||
83 | /** |
||
84 | * |
||
85 | * Iterator: gets the current rule. |
||
86 | * |
||
87 | * @return RuleInterface |
||
88 | * |
||
89 | */ |
||
90 | 8 | public function current() |
|
110 | |||
111 | /** |
||
112 | * |
||
113 | * Iterator: gets the current rule key. |
||
114 | * |
||
115 | * @return mixed |
||
116 | * |
||
117 | */ |
||
118 | 1 | public function key() |
|
122 | |||
123 | /** |
||
124 | * |
||
125 | * Iterator: moves the iterator forward to the next rule. |
||
126 | * |
||
127 | * @return null |
||
128 | * |
||
129 | */ |
||
130 | 6 | public function next() |
|
134 | |||
135 | /** |
||
136 | * |
||
137 | * Iterator: rewinds to the first rule. |
||
138 | * |
||
139 | * @return null |
||
140 | * |
||
141 | */ |
||
142 | 6 | public function rewind() |
|
146 | |||
147 | /** |
||
148 | * |
||
149 | * Iterator: is the current position valid? |
||
150 | * |
||
151 | * @return bool |
||
152 | * |
||
153 | */ |
||
154 | 6 | public function valid() |
|
158 | } |
||
159 |