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
|
42 |
|
public final function create($object, StrategyContainer $strategies, Context $context = null) |
|
|
|
|
16
|
|
|
{ |
17
|
42 |
|
if (! $this->matches($object)) { |
18
|
8 |
|
throw new \InvalidArgumentException( |
19
|
8 |
|
sprintf('%s cannot handle objects with the type %s', |
20
|
8 |
|
__CLASS__, |
21
|
8 |
|
is_object($object) ? get_class($object) : gettype($object) |
22
|
8 |
|
) |
23
|
8 |
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
34 |
|
return $this->doCreate($object, $strategies, $context); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
abstract protected function doCreate($object, StrategyContainer $strategies, Context $context = null); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Node|PropertyIterator|ClassConstantIterator $stmt |
33
|
|
|
* @param StrategyContainer $strategies |
34
|
|
|
* @param Context $context |
35
|
|
|
* @return Element |
36
|
|
|
*/ |
37
|
14 |
|
protected function createMember($stmt, StrategyContainer $strategies, Context $context = null) |
38
|
|
|
{ |
39
|
14 |
|
$strategy = $strategies->findMatching($stmt); |
40
|
14 |
|
return $strategy->create($stmt, $strategies, $context); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Doc $docBlock |
45
|
|
|
* @param StrategyContainer $strategies |
46
|
|
|
* @param Context $context |
47
|
|
|
* @return null|\phpDocumentor\Reflection\DocBlock |
48
|
|
|
*/ |
49
|
28 |
|
protected function createDocBlock(Doc $docBlock = null, StrategyContainer $strategies, Context $context = null) |
|
|
|
|
50
|
|
|
{ |
51
|
28 |
|
if ($docBlock === null) { |
52
|
22 |
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
6 |
|
return $this->createMember($docBlock, $strategies, $context); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|