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