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
|
|
|
namespace phpDocumentor\Reflection\Php\Factory; |
14
|
|
|
|
15
|
|
|
use InvalidArgumentException; |
16
|
|
|
use phpDocumentor\Reflection\Element; |
17
|
|
|
use phpDocumentor\Reflection\Fqsen; |
18
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; |
19
|
|
|
use phpDocumentor\Reflection\Php\StrategyContainer; |
20
|
|
|
use phpDocumentor\Reflection\Php\Trait_ as TraitElement; |
21
|
|
|
use phpDocumentor\Reflection\Types\Context; |
22
|
|
|
use PhpParser\Comment\Doc; |
23
|
|
|
use PhpParser\Node; |
24
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
25
|
|
|
use PhpParser\Node\Stmt\Property as PropertyNode; |
26
|
|
|
use PhpParser\Node\Stmt\Trait_ as TraitNode; |
27
|
|
|
use PhpParser\Node\Stmt\TraitUse; |
28
|
|
|
|
29
|
|
|
// @codingStandardsIgnoreStart |
30
|
|
|
final class Trait_ extends AbstractFactory implements ProjectFactoryStrategy |
31
|
|
|
// @codingStandardsIgnoreEnd |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Returns true when the strategy is able to handle the object. |
35
|
|
|
* |
36
|
|
|
* @param TraitNode $object object to check. |
37
|
|
|
* @return boolean |
38
|
|
|
*/ |
39
|
1 |
|
public function matches($object) |
40
|
|
|
{ |
41
|
1 |
|
return $object instanceof TraitNode; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Creates an TraitElement out of the given object. |
46
|
|
|
* Since an object might contain other objects that need to be converted the $factory is passed so it can be |
47
|
|
|
* used to create nested Elements. |
48
|
|
|
* |
49
|
|
|
* @param TraitNode $object object to convert to an TraitElement |
50
|
|
|
* @param StrategyContainer $strategies used to convert nested objects. |
51
|
|
|
* @param Context $context |
52
|
|
|
* @return TraitElement |
53
|
|
|
*/ |
54
|
5 |
|
protected function doCreate($object, StrategyContainer $strategies, Context $context = null) |
55
|
|
|
{ |
56
|
5 |
|
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); |
57
|
|
|
|
58
|
5 |
|
$trait = new TraitElement($object->fqsen, $docBlock); |
|
|
|
|
59
|
|
|
|
60
|
5 |
|
if (isset($object->stmts)) { |
61
|
3 |
|
foreach ($object->stmts as $stmt) { |
62
|
3 |
|
switch (get_class($stmt)) { |
63
|
3 |
|
case PropertyNode::class: |
64
|
1 |
|
$properties = new PropertyIterator($stmt); |
|
|
|
|
65
|
1 |
|
foreach ($properties as $property) { |
66
|
1 |
|
$element = $this->createMember($property, $strategies, $context); |
67
|
1 |
|
$trait->addProperty($element); |
|
|
|
|
68
|
1 |
|
} |
69
|
1 |
|
break; |
70
|
2 |
|
case ClassMethod::class: |
71
|
1 |
|
$method = $this->createMember($stmt, $strategies, $context); |
72
|
1 |
|
$trait->addMethod($method); |
|
|
|
|
73
|
1 |
|
break; |
74
|
1 |
|
case TraitUse::class: |
75
|
2 |
|
foreach ($stmt->traits as $use) { |
|
|
|
|
76
|
1 |
|
$trait->addUsedTrait(new Fqsen('\\'. $use->toString())); |
77
|
1 |
|
} |
78
|
1 |
|
break; |
79
|
3 |
|
} |
80
|
3 |
|
} |
81
|
3 |
|
} |
82
|
|
|
|
83
|
5 |
|
return $trait; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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.