22
33namespace Illuminate \View ;
44
5+ use ArrayIterator ;
56use Closure ;
67use Illuminate \Container \Container ;
78use Illuminate \Contracts \Support \DeferringDisplayableValue ;
9+ use Illuminate \Support \Enumerable ;
810use Illuminate \Support \Str ;
11+ use IteratorAggregate ;
912use ReflectionClass ;
1013use ReflectionMethod ;
1114use ReflectionProperty ;
@@ -197,7 +200,7 @@ protected function createInvokableVariable(string $method)
197200 {
198201 return new class (function () use ($ method ) {
199202 return $ this ->{$ method }();
200- }) implements DeferringDisplayableValue {
203+ }) implements DeferringDisplayableValue, IteratorAggregate {
201204 protected $ callable ;
202205
203206 public function __construct (Closure $ callable )
@@ -210,6 +213,23 @@ public function resolveDisplayableValue()
210213 return $ this ->__invoke ();
211214 }
212215
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+
213233 public function __invoke ()
214234 {
215235 return call_user_func ($ this ->callable );
@@ -219,7 +239,6 @@ public function __toString()
219239 {
220240 return (string ) $ this ->__invoke ();
221241 }
222-
223242 };
224243 }
225244
0 commit comments