Skip to content

Commit 08c4012

Browse files
committed
add more proxy methods to deferred value
1 parent 28571f8 commit 08c4012

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Illuminate/View/Component.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace Illuminate\View;
44

5+
use ArrayIterator;
56
use Closure;
67
use Illuminate\Container\Container;
78
use Illuminate\Contracts\Support\DeferringDisplayableValue;
9+
use Illuminate\Support\Enumerable;
810
use Illuminate\Support\Str;
11+
use IteratorAggregate;
912
use ReflectionClass;
1013
use ReflectionMethod;
1114
use 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

Comments
 (0)