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