1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com) |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* @link http://phpdoc.org |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpDocumentor\Descriptor\Builder\Reflector; |
13
|
|
|
|
14
|
|
|
use phpDocumentor\Descriptor\InterfaceDescriptor; |
15
|
|
|
use phpDocumentor\Reflection\ClassReflector\MethodReflector; |
16
|
|
|
use phpDocumentor\Reflection\ConstantReflector; |
17
|
|
|
use phpDocumentor\Reflection\InterfaceReflector; |
18
|
|
|
use phpDocumentor\Reflection\Php\Constant; |
19
|
|
|
use phpDocumentor\Reflection\Php\Interface_; |
20
|
|
|
use phpDocumentor\Reflection\Php\Method; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Assembles an InterfaceDescriptor using an InterfaceReflector. |
24
|
|
|
*/ |
25
|
|
|
class InterfaceAssembler extends AssemblerAbstract |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Creates a Descriptor from the provided data. |
29
|
|
|
* |
30
|
|
|
* @param Interface_ $data |
31
|
|
|
* |
32
|
|
|
* @return InterfaceDescriptor |
33
|
|
|
*/ |
34
|
|
|
public function create($data) |
35
|
|
|
{ |
36
|
|
|
$interfaceDescriptor = new InterfaceDescriptor(); |
37
|
|
|
|
38
|
|
|
$interfaceDescriptor->setFullyQualifiedStructuralElementName($data->getFqsen()); |
39
|
|
|
$interfaceDescriptor->setName($data->getName()); |
40
|
|
|
$interfaceDescriptor->setLine($data->getLocation()->getLineNumber()); |
41
|
|
|
$interfaceDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: ''); |
|
|
|
|
42
|
|
|
|
43
|
|
|
// Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself |
44
|
|
|
$interfaceDescriptor->setNamespace(substr($data->getFqsen(), 0, -strlen($data->getName())-1)); |
45
|
|
|
|
46
|
|
|
$this->assembleDocBlock($data->getDocBlock(), $interfaceDescriptor); |
47
|
|
|
$this->addConstants($data->getConstants(), $interfaceDescriptor); |
48
|
|
|
$this->addMethods($data->getMethods(), $interfaceDescriptor); |
49
|
|
|
|
50
|
|
|
foreach ($data->getParents() as $interfaceClassName) { |
51
|
|
|
$interfaceDescriptor->getParent()->set((string)$interfaceClassName, $interfaceClassName); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $interfaceDescriptor; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Registers the child constants with the generated Interface Descriptor. |
59
|
|
|
* |
60
|
|
|
* @param Constant[] $constants |
61
|
|
|
* @param InterfaceDescriptor $interfaceDescriptor |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
protected function addConstants($constants, $interfaceDescriptor) |
66
|
|
|
{ |
67
|
|
|
foreach ($constants as $constant) { |
68
|
|
|
$constantDescriptor = $this->getBuilder()->buildDescriptor($constant); |
69
|
|
|
if ($constantDescriptor) { |
70
|
|
|
$constantDescriptor->setParent($interfaceDescriptor); |
71
|
|
|
$interfaceDescriptor->getConstants()->set($constantDescriptor->getName(), $constantDescriptor); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Registers the child methods with the generated Interface Descriptor. |
78
|
|
|
* |
79
|
|
|
* @param Method[] $methods |
80
|
|
|
* @param InterfaceDescriptor $interfaceDescriptor |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
protected function addMethods($methods, $interfaceDescriptor) |
85
|
|
|
{ |
86
|
|
|
foreach ($methods as $method) { |
87
|
|
|
$methodDescriptor = $this->getBuilder()->buildDescriptor($method); |
88
|
|
|
if ($methodDescriptor) { |
89
|
|
|
$methodDescriptor->setParent($interfaceDescriptor); |
90
|
|
|
$interfaceDescriptor->getMethods()->set($methodDescriptor->getName(), $methodDescriptor); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: