|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace phpDocumentor\Reflection\Php\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use phpDocumentor\Reflection\Element; |
|
6
|
|
|
use phpDocumentor\Reflection\Php\StrategyContainer; |
|
7
|
|
|
use phpDocumentor\Reflection\Types\Context; |
|
8
|
|
|
use PhpParser\Comment\Doc; |
|
9
|
|
|
use PhpParser\Node; |
|
10
|
|
|
|
|
11
|
|
|
abstract class AbstractFactory |
|
12
|
|
|
{ |
|
13
|
|
|
abstract public function matches($object); |
|
14
|
|
|
|
|
15
|
|
|
public function create($object, StrategyContainer $strategies, Context $context = null) |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
if (! $this->matches($object)) { |
|
18
|
|
|
throw new \InvalidArgumentException( |
|
19
|
|
|
sprintf('%s cannot handle objects with the type %s', |
|
20
|
|
|
__CLASS__, |
|
21
|
|
|
is_object($object) ? get_class($object) : gettype($object) |
|
22
|
|
|
) |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
abstract protected function doCreate($object, StrategyContainer $strategies, Context $context = null); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param Node|PropertyIterator|ClassConstantIterator $stmt |
|
31
|
|
|
* @param StrategyContainer $strategies |
|
32
|
|
|
* @param Context $context |
|
33
|
|
|
* @return Element |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function createMember($stmt, StrategyContainer $strategies, Context $context = null) |
|
36
|
|
|
{ |
|
37
|
|
|
$strategy = $strategies->findMatching($stmt); |
|
38
|
|
|
return $strategy->create($stmt, $strategies, $context); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param Doc $docBlock |
|
43
|
|
|
* @param StrategyContainer $strategies |
|
44
|
|
|
* @param Context $context |
|
45
|
|
|
* @return null|\phpDocumentor\Reflection\DocBlock |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function createDocBlock(Doc $docBlock = null, StrategyContainer $strategies, Context $context = null) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
if ($docBlock === null) { |
|
50
|
|
|
return null; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $this->createMember($docBlock, $strategies, $context); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.