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
|
|
|
namespace phpDocumentor\Reflection\Php; |
14
|
|
|
|
15
|
|
|
use OutOfBoundsException; |
16
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; |
17
|
|
|
|
18
|
|
|
final class ProjectFactoryStrategies implements StrategyContainer |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var ProjectFactoryStrategy[] |
22
|
|
|
*/ |
23
|
|
|
private $strategies; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Initializes the factory with a number of strategies. |
27
|
|
|
* |
28
|
|
|
* @param ProjectFactoryStrategy[] $strategies |
29
|
|
|
*/ |
30
|
|
|
public function __construct(array $strategies) |
31
|
|
|
{ |
32
|
|
|
foreach ($strategies as $strategy) { |
33
|
|
|
$this->addStrategy($strategy); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$this->strategies = $strategies; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Find the ProjectFactoryStrategy that matches $object. |
42
|
|
|
* |
43
|
|
|
* @param mixed $object |
44
|
|
|
* @return ProjectFactoryStrategy |
45
|
|
|
* @throws OutOfBoundsException when no matching strategy was found. |
46
|
|
|
*/ |
47
|
2 |
|
public function findMatching($object) |
48
|
|
|
{ |
49
|
2 |
|
foreach ($this->strategies as $strategy) { |
50
|
1 |
|
if ($strategy->matches($object)) { |
51
|
1 |
|
return $strategy; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
throw new OutOfBoundsException( |
56
|
1 |
|
sprintf( |
57
|
1 |
|
'No matching factory found for %s', |
58
|
1 |
|
is_object($object) ? get_class($object) : gettype($object) |
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Add a strategy to this container. |
65
|
|
|
* |
66
|
|
|
* @param ProjectFactoryStrategy $strategy |
67
|
|
|
*/ |
68
|
|
|
public function addStrategy(ProjectFactoryStrategy $strategy) |
69
|
|
|
{ |
70
|
|
|
$this->strategies[] = $strategy; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|