1 | <?php |
||
12 | class FunctionScope implements IFunctionScope |
||
13 | { |
||
14 | /** |
||
15 | * @var object|null |
||
16 | */ |
||
17 | protected $thisObject; |
||
18 | |||
19 | /** |
||
20 | * @var string|null |
||
21 | */ |
||
22 | protected $thisType; |
||
23 | |||
24 | /** |
||
25 | * @var string|null |
||
26 | */ |
||
27 | protected $scopeType; |
||
28 | |||
29 | /** |
||
30 | * @var array<string, mixed> |
||
31 | */ |
||
32 | protected $variableValueMap; |
||
33 | |||
34 | public function __construct( |
||
44 | |||
45 | /** |
||
46 | * Creates a function scope instance from the supplied reflection and callable. |
||
47 | * |
||
48 | * @param \ReflectionFunctionAbstract $reflection |
||
49 | * @param callable $callable |
||
50 | * |
||
51 | * @return self |
||
52 | */ |
||
53 | public static function fromReflection(\ReflectionFunctionAbstract $reflection, callable $callable) |
||
54 | { |
||
55 | if (is_array($callable)) { |
||
56 | /** @var $reflection \ReflectionMethod */ |
||
57 | $thisObject = is_object($callable[0]) ? $callable[0] : null; |
||
58 | $scopeType = $reflection->getDeclaringClass()->getName(); |
||
|
|||
59 | } elseif (is_object($callable) && !($callable instanceof \Closure)) { |
||
60 | /** @var $reflection \ReflectionMethod */ |
||
61 | $thisObject = $callable; |
||
62 | $scopeType = $reflection->getDeclaringClass()->getName(); |
||
63 | } elseif ($reflection->isClosure()) { |
||
64 | $thisObject = $reflection->getClosureThis(); |
||
65 | $scopeClass = $reflection->getClosureScopeClass(); |
||
66 | $scopeType = $scopeClass === null ? null : $scopeClass->getName(); |
||
67 | } else { |
||
68 | $thisObject = null; |
||
69 | $scopeType = null; |
||
70 | } |
||
71 | $variableTable = $reflection->getStaticVariables(); |
||
72 | |||
73 | return new self($thisObject, $scopeType, $variableTable); |
||
74 | } |
||
75 | |||
76 | public function hasThis() |
||
80 | |||
81 | public function getThis() |
||
85 | |||
86 | public function getThisType() |
||
90 | |||
91 | public function getScopeType() |
||
95 | |||
96 | public function getVariableTable() |
||
100 | |||
101 | public function asEvaluationContext(array $variableTable = [], $namespace = null) |
||
111 | } |
||
112 |