1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection\Php\Factory; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use phpDocumentor\Reflection\Element; |
18
|
|
|
use phpDocumentor\Reflection\Fqsen; |
19
|
|
|
use phpDocumentor\Reflection\Php\Class_ as ClassElement; |
20
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; |
21
|
|
|
use phpDocumentor\Reflection\Php\StrategyContainer; |
22
|
|
|
use phpDocumentor\Reflection\Types\Context; |
23
|
|
|
use PhpParser\Node; |
24
|
|
|
use PhpParser\Node\Stmt\Class_ as ClassNode; |
25
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
26
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
27
|
|
|
use PhpParser\Node\Stmt\Property as PropertyNode; |
28
|
|
|
use PhpParser\Comment\Doc; |
29
|
|
|
use PhpParser\Node\Stmt\TraitUse; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Strategy to create a ClassElement including all sub elements. |
33
|
|
|
*/ |
34
|
|
|
// @codingStandardsIgnoreStart |
35
|
|
|
final class Class_ extends AbstractFactory implements ProjectFactoryStrategy |
36
|
|
|
// @codingStandardsIgnoreEnd |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Returns true when the strategy is able to handle the object. |
40
|
|
|
* |
41
|
|
|
* @param object $object object to check. |
42
|
|
|
* @return boolean |
43
|
|
|
*/ |
44
|
1 |
|
public function matches($object) |
45
|
|
|
{ |
46
|
1 |
|
return $object instanceof ClassNode; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Creates an ClassElement out of the given object. |
51
|
|
|
* Since an object might contain other objects that need to be converted the $factory is passed so it can be |
52
|
|
|
* used to create nested Elements. |
53
|
|
|
* |
54
|
|
|
* @param ClassNode $object object to convert to an Element |
55
|
|
|
* @param StrategyContainer $strategies used to convert nested objects. |
56
|
|
|
* @param Context $context of the created object |
57
|
|
|
* @return ClassElement |
58
|
|
|
*/ |
59
|
8 |
|
protected function doCreate($object, StrategyContainer $strategies, Context $context = null) |
60
|
|
|
{ |
61
|
8 |
|
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); |
62
|
|
|
|
63
|
8 |
|
$classElement = new ClassElement( |
64
|
8 |
|
$object->fqsen, |
|
|
|
|
65
|
8 |
|
$docBlock, |
|
|
|
|
66
|
8 |
|
$object->extends ? new Fqsen('\\' . $object->extends) : null, |
67
|
8 |
|
$object->isAbstract(), |
68
|
8 |
|
$object->isFinal() |
69
|
8 |
|
); |
70
|
|
|
|
71
|
8 |
|
if (isset($object->implements)) { |
72
|
1 |
|
foreach ($object->implements as $interfaceClassName) { |
73
|
1 |
|
$classElement->addInterface( |
74
|
1 |
|
new Fqsen('\\' . $interfaceClassName->toString()) |
75
|
1 |
|
); |
76
|
1 |
|
} |
77
|
1 |
|
} |
78
|
|
|
|
79
|
8 |
|
if (isset($object->stmts)) { |
80
|
4 |
|
foreach ($object->stmts as $stmt) { |
81
|
4 |
|
switch (get_class($stmt)) { |
82
|
4 |
|
case TraitUse::class: |
83
|
1 |
|
foreach ($stmt->traits as $use) { |
|
|
|
|
84
|
1 |
|
$classElement->addUsedTrait(new Fqsen('\\'. $use->toString())); |
85
|
1 |
|
} |
86
|
1 |
|
break; |
87
|
3 |
|
case PropertyNode::class: |
88
|
1 |
|
$properties = new PropertyIterator($stmt); |
|
|
|
|
89
|
1 |
|
foreach ($properties as $property) { |
90
|
1 |
|
$element = $this->createMember($property, $strategies, $context); |
91
|
1 |
|
$classElement->addProperty($element); |
|
|
|
|
92
|
1 |
|
} |
93
|
1 |
|
break; |
94
|
2 |
|
case ClassMethod::class: |
95
|
1 |
|
$method = $this->createMember($stmt, $strategies, $context); |
96
|
1 |
|
$classElement->addMethod($method); |
|
|
|
|
97
|
1 |
|
break; |
98
|
1 |
|
case ClassConst::class: |
99
|
1 |
|
$constants = new ClassConstantIterator($stmt); |
|
|
|
|
100
|
1 |
|
foreach ($constants as $const) { |
101
|
1 |
|
$element = $this->createMember($const, $strategies, $context); |
102
|
1 |
|
$classElement->addConstant($element); |
|
|
|
|
103
|
1 |
|
} |
104
|
1 |
|
break; |
105
|
4 |
|
} |
106
|
4 |
|
} |
107
|
4 |
|
} |
108
|
|
|
|
109
|
8 |
|
return $classElement; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.