Skip to content

Commit

Permalink
add more proxy methods to deferred value
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 28, 2020
1 parent 28571f8 commit 08c4012
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Illuminate/View/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Illuminate\View;

use ArrayIterator;
use Closure;
use Illuminate\Container\Container;
use Illuminate\Contracts\Support\DeferringDisplayableValue;
use Illuminate\Support\Enumerable;
use Illuminate\Support\Str;
use IteratorAggregate;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
Expand Down Expand Up @@ -197,7 +200,7 @@ protected function createInvokableVariable(string $method)
{
return new class(function () use ($method) {
return $this->{$method}();
}) implements DeferringDisplayableValue {
}) implements DeferringDisplayableValue, IteratorAggregate {
protected $callable;

public function __construct(Closure $callable)
Expand All @@ -210,6 +213,23 @@ public function resolveDisplayableValue()
return $this->__invoke();
}

public function getIterator()
{
$result = $this->__invoke();

return new ArrayIterator($result instanceof Enumerable ? $result->all() : $result);
}

public function __get($key)
{
return $this->__invoke()->{$key};
}

public function __call($method, $parameters)
{
return $this->__invoke()->{$method}(...$parameters);
}

public function __invoke()
{
return call_user_func($this->callable);
Expand All @@ -219,7 +239,6 @@ public function __toString()
{
return (string) $this->__invoke();
}

};
}

Expand Down

0 comments on commit 08c4012

Please sign in to comment.