-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeExtensionCompilerPass.php
More file actions
49 lines (41 loc) · 1.48 KB
/
TypeExtensionCompilerPass.php
File metadata and controls
49 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
* This file is part of the enhavo package.
*
* (c) WE ARE INDEED GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Enhavo\Component\Type;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class TypeExtensionCompilerPass implements CompilerPassInterface
{
public function __construct(
private string $namespace,
private string $tagName,
) {
}
public function process(ContainerBuilder $container)
{
$registryDefinitionId = sprintf('%s[%s]', RegistryInterface::class, $this->namespace);
$registryDefinition = $container->getDefinition($registryDefinitionId);
$taggedServices = $container->findTaggedServiceIds($this->tagName);
foreach ($taggedServices as $id => $tagAttributes) {
$priority = 10;
foreach ($tagAttributes as $tagAttribute) {
if (isset($tagAttribute['priority'])) {
$priority = $tagAttribute['priority'];
break;
}
}
$tagServiceDefinition = $container->getDefinition($id);
$tagServiceDefinition->setPublic(true);
$registryDefinition->addMethodCall(
'registerExtension',
[$tagServiceDefinition->getClass() ?: $id, $id, $priority]
);
}
}
}