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\ProjectFactoryStrategy; |
20
|
|
|
use phpDocumentor\Reflection\Php\StrategyContainer; |
21
|
|
|
use phpDocumentor\Reflection\Types\Context; |
22
|
|
|
use PhpParser\Comment\Doc; |
23
|
|
|
use PhpParser\Node; |
24
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
25
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
26
|
|
|
use PhpParser\Node\Stmt\Interface_ as InterfaceNode; |
27
|
|
|
use phpDocumentor\Reflection\Php\Interface_ as InterfaceElement; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Strategy to create a InterfaceElement including all sub elements. |
31
|
|
|
*/ |
32
|
|
|
// @codingStandardsIgnoreStart |
33
|
|
|
final class Interface_ extends AbstractFactory implements ProjectFactoryStrategy |
34
|
|
|
// @codingStandardsIgnoreEnd |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns true when the strategy is able to handle the object. |
39
|
|
|
* |
40
|
|
|
* @param InterfaceNode $object object to check. |
41
|
|
|
* @return boolean |
42
|
|
|
*/ |
43
|
1 |
|
public function matches($object) |
44
|
|
|
{ |
45
|
1 |
|
return $object instanceof InterfaceNode; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Creates an Interface_ out of the given object. |
50
|
|
|
* Since an object might contain other objects that need to be converted the $factory is passed so it can be |
51
|
|
|
* used to create nested Elements. |
52
|
|
|
* |
53
|
|
|
* @param InterfaceNode $object object to convert to an Element |
54
|
|
|
* @param StrategyContainer $strategies used to convert nested objects. |
55
|
|
|
* @param Context $context of the created object |
56
|
|
|
* @return InterfaceElement |
57
|
|
|
*/ |
58
|
4 |
|
protected function doCreate($object, StrategyContainer $strategies, Context $context = null) |
59
|
|
|
{ |
60
|
4 |
|
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); |
61
|
4 |
|
$parents = array(); |
62
|
4 |
|
foreach ($object->extends as $extend) { |
63
|
|
|
$parents['\\' . (string)$extend] = new Fqsen('\\' . (string)$extend); |
64
|
4 |
|
} |
65
|
|
|
|
66
|
4 |
|
$interface = new InterfaceElement($object->fqsen, $parents, $docBlock); |
|
|
|
|
67
|
|
|
|
68
|
4 |
|
if (isset($object->stmts)) { |
69
|
2 |
|
foreach ($object->stmts as $stmt) { |
70
|
2 |
|
switch (get_class($stmt)) { |
71
|
2 |
|
case ClassMethod::class: |
72
|
1 |
|
$method = $this->createMember($stmt, $strategies, $context); |
73
|
1 |
|
$interface->addMethod($method); |
|
|
|
|
74
|
1 |
|
break; |
75
|
1 |
|
case ClassConst::class: |
76
|
1 |
|
$constants = new ClassConstantIterator($stmt); |
|
|
|
|
77
|
1 |
|
foreach ($constants as $const) { |
78
|
1 |
|
$element = $this->createMember($const, $strategies, $context); |
79
|
1 |
|
$interface->addConstant($element); |
|
|
|
|
80
|
1 |
|
} |
81
|
1 |
|
break; |
82
|
2 |
|
} |
83
|
2 |
|
} |
84
|
2 |
|
} |
85
|
|
|
|
86
|
4 |
|
return $interface; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.