Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\View;
4
 
5
use ArrayIterator;
6
use Closure;
7
use Illuminate\Contracts\Support\DeferringDisplayableValue;
8
use Illuminate\Support\Enumerable;
9
use IteratorAggregate;
10
use Traversable;
11
 
12
class InvokableComponentVariable implements DeferringDisplayableValue, IteratorAggregate
13
{
14
    /**
15
     * The callable instance to resolve the variable value.
16
     *
17
     * @var \Closure
18
     */
19
    protected $callable;
20
 
21
    /**
22
     * Create a new variable instance.
23
     *
24
     * @param  \Closure  $callable
25
     * @return void
26
     */
27
    public function __construct(Closure $callable)
28
    {
29
        $this->callable = $callable;
30
    }
31
 
32
    /**
33
     * Resolve the displayable value that the class is deferring.
34
     *
35
     * @return \Illuminate\Contracts\Support\Htmlable|string
36
     */
37
    public function resolveDisplayableValue()
38
    {
39
        return $this->__invoke();
40
    }
41
 
42
    /**
43
     * Get an interator instance for the variable.
44
     *
45
     * @return \ArrayIterator
46
     */
47
    public function getIterator(): Traversable
48
    {
49
        $result = $this->__invoke();
50
 
51
        return new ArrayIterator($result instanceof Enumerable ? $result->all() : $result);
52
    }
53
 
54
    /**
55
     * Dynamically proxy attribute access to the variable.
56
     *
57
     * @param  string  $key
58
     * @return mixed
59
     */
60
    public function __get($key)
61
    {
62
        return $this->__invoke()->{$key};
63
    }
64
 
65
    /**
66
     * Dynamically proxy method access to the variable.
67
     *
68
     * @param  string  $method
69
     * @param  array  $parameters
70
     * @return mixed
71
     */
72
    public function __call($method, $parameters)
73
    {
74
        return $this->__invoke()->{$method}(...$parameters);
75
    }
76
 
77
    /**
78
     * Resolve the variable.
79
     *
80
     * @return mixed
81
     */
82
    public function __invoke()
83
    {
84
        return call_user_func($this->callable);
85
    }
86
 
87
    /**
88
     * Resolve the variable as a string.
89
     *
90
     * @return mixed
91
     */
92
    public function __toString()
93
    {
94
        return (string) $this->__invoke();
95
    }
96
}