1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link https://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use phpDocumentor\Reflection\Php\ProjectFactoryStrategies; |
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
20
|
|
|
use function array_column; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Custom Compiler pass to help symfony to construct the ProjectFactoryStrategies |
24
|
|
|
* |
25
|
|
|
* All strategies defined in {@see \phpDocumentor\Reflection\Php\Factory} are injected automatically by our service |
26
|
|
|
* configuration with a default priority. In some situations this needs to be overwritten. This compiler pass helps us |
27
|
|
|
* with that part. It will find the tagged services and add them to the {@see ProjectFactoryStrategies}, if multiple |
28
|
|
|
* `phpdoc.reflection.strategy` tags are defined it will inject them multiple times with different priority. |
29
|
|
|
* If no priority is defined the default will be used. |
30
|
|
|
*/ |
31
|
|
|
final class ReflectionProjectFactoryStrategyPass implements CompilerPassInterface |
32
|
|
|
{ |
33
|
2 |
|
public function process(ContainerBuilder $container) : void |
34
|
|
|
{ |
35
|
2 |
|
$strategies = $container->getDefinition(ProjectFactoryStrategies::class); |
36
|
2 |
|
foreach ($container->findTaggedServiceIds('phpdoc.reflection.strategy') as $id => $tags) { |
37
|
2 |
|
$priotities = array_column($tags, 'priority'); |
38
|
2 |
|
if (empty($priotities)) { |
39
|
2 |
|
$strategies->addMethodCall( |
40
|
2 |
|
'addStrategy', |
41
|
|
|
[ |
42
|
2 |
|
new Reference($id), |
43
|
|
|
ProjectFactoryStrategies::DEFAULT_PRIORITY, |
44
|
|
|
] |
45
|
|
|
); |
46
|
|
|
|
47
|
2 |
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
foreach ($priotities as $priotity) { |
51
|
1 |
|
$strategies->addMethodCall( |
52
|
1 |
|
'addStrategy', |
53
|
|
|
[ |
54
|
1 |
|
new Reference($id), |
55
|
1 |
|
$priotity ?? ProjectFactoryStrategies::DEFAULT_PRIORITY, |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
2 |
|
} |
61
|
|
|
} |
62
|
|
|
|