2
2
3
3
namespace Illuminate \View ;
4
4
5
+ use ArrayIterator ;
5
6
use Closure ;
6
7
use Illuminate \Container \Container ;
7
8
use Illuminate \Contracts \Support \DeferringDisplayableValue ;
9
+ use Illuminate \Support \Enumerable ;
8
10
use Illuminate \Support \Str ;
11
+ use IteratorAggregate ;
9
12
use ReflectionClass ;
10
13
use ReflectionMethod ;
11
14
use ReflectionProperty ;
@@ -197,7 +200,7 @@ protected function createInvokableVariable(string $method)
197
200
{
198
201
return new class (function () use ($ method ) {
199
202
return $ this ->{$ method }();
200
- }) implements DeferringDisplayableValue {
203
+ }) implements DeferringDisplayableValue, IteratorAggregate {
201
204
protected $ callable ;
202
205
203
206
public function __construct (Closure $ callable )
@@ -210,6 +213,23 @@ public function resolveDisplayableValue()
210
213
return $ this ->__invoke ();
211
214
}
212
215
216
+ public function getIterator ()
217
+ {
218
+ $ result = $ this ->__invoke ();
219
+
220
+ return new ArrayIterator ($ result instanceof Enumerable ? $ result ->all () : $ result );
221
+ }
222
+
223
+ public function __get ($ key )
224
+ {
225
+ return $ this ->__invoke ()->{$ key };
226
+ }
227
+
228
+ public function __call ($ method , $ parameters )
229
+ {
230
+ return $ this ->__invoke ()->{$ method }(...$ parameters );
231
+ }
232
+
213
233
public function __invoke ()
214
234
{
215
235
return call_user_func ($ this ->callable );
@@ -219,7 +239,6 @@ public function __toString()
219
239
{
220
240
return (string ) $ this ->__invoke ();
221
241
}
222
-
223
242
};
224
243
}
225
244
0 commit comments