|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Parser Reflection API |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright 2015, Lisachenko Alexander <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Go\ParserReflection; |
|
12
|
|
|
|
|
13
|
|
|
use Go\ParserReflection\Traits\InternalPropertiesEmulationTrait; |
|
14
|
|
|
use Go\ParserReflection\Traits\ReflectionClassLikeTrait; |
|
15
|
|
|
use PhpParser\Node\Name; |
|
16
|
|
|
use PhpParser\Node\Stmt\ClassLike; |
|
17
|
|
|
use ReflectionObject as InternalReflectionObject; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* AST-based reflection for an object |
|
21
|
|
|
* |
|
22
|
|
|
* Typically, this class won't be used on parsing level, because if we have an instance of object, |
|
23
|
|
|
* then we can initialize a default ReflectionObject for it. |
|
24
|
|
|
*/ |
|
25
|
|
|
class ReflectionObject extends InternalReflectionObject |
|
26
|
|
|
{ |
|
27
|
|
|
use ReflectionClassLikeTrait, InternalPropertiesEmulationTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Instance of object |
|
31
|
|
|
* |
|
32
|
|
|
* @var object |
|
33
|
|
|
*/ |
|
34
|
|
|
private $instance; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Initializes reflection instance |
|
38
|
|
|
* |
|
39
|
|
|
* @param object $instance Instance of object |
|
40
|
|
|
* @param ClassLike $classLikeNode AST node for class definition |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct($instance, ClassLike $classLikeNode = null) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->instance = $instance; |
|
45
|
|
|
$fullClassName = get_class($instance); |
|
46
|
|
|
$namespaceParts = explode('\\', $fullClassName); |
|
47
|
|
|
$this->className = array_pop($namespaceParts); |
|
48
|
|
|
// Let's unset original read-only property to have a control over it via __get |
|
49
|
|
|
unset($this->name); |
|
50
|
|
|
|
|
51
|
|
|
$this->namespaceName = join('\\', $namespaceParts); |
|
52
|
|
|
|
|
53
|
|
|
$this->classLikeNode = $classLikeNode ?: ReflectionEngine::parseClass($fullClassName); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Emulating original behaviour of reflection |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __debugInfo() |
|
60
|
|
|
{ |
|
61
|
|
|
return array( |
|
62
|
|
|
'name' => $this->getName() |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Implementation of internal reflection initialization |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function __initialize() |
|
72
|
|
|
{ |
|
73
|
|
|
parent::__construct($this->instance); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|