1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* (c) Yaroslav Honcharuk <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Yarhon\RouteGuardBundle\DependencyInjection\Compiler; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; |
16
|
|
|
use Yarhon\RouteGuardBundle\Security\TestProvider\ProviderAggregate; |
17
|
|
|
use Yarhon\RouteGuardBundle\Security\TestResolver\SymfonySecurityResolver; |
18
|
|
|
use Yarhon\RouteGuardBundle\Controller\ArgumentResolver; |
19
|
|
|
use Yarhon\RouteGuardBundle\Security\AuthorizationChecker\DelegatingAuthorizationChecker; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Injects tagged services collection as a service argument. |
23
|
|
|
* Service argument must be initialized by an empty collection. |
24
|
|
|
* |
25
|
|
|
* We use CompilerPass to inject tagged services for compatibility with Symfony 3.3. |
26
|
|
|
* Starting from Symfony 3.4 we can use <argument type="tagged" tag="..." /> and remove this CompilerPass. |
27
|
|
|
* |
28
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class InjectTaggedServicesPass implements CompilerPassInterface |
31
|
|
|
{ |
32
|
|
|
use PriorityTaggedServiceTrait; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
22 |
|
public function process(ContainerBuilder $container) |
38
|
|
|
{ |
39
|
22 |
|
$this->injectAsArgument($container, [ProviderAggregate::class, 0], 'yarhon_route_guard.test_provider'); |
40
|
22 |
|
$this->injectAsArgument($container, [SymfonySecurityResolver::class, 0], 'yarhon_route_guard.test_resolver.symfony_security'); |
41
|
22 |
|
$this->injectAsArgument($container, [ArgumentResolver::class, 3], 'yarhon_route_guard.argument_value_resolver'); |
42
|
22 |
|
$this->injectAsArgument($container, [DelegatingAuthorizationChecker::class, 0], 'yarhon_route_guard.authorization_checker'); |
43
|
22 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ContainerBuilder $container |
47
|
|
|
* @param array $destination |
48
|
|
|
* @param string $tagName |
49
|
|
|
*/ |
50
|
22 |
|
private function injectAsArgument(ContainerBuilder $container, $destination, $tagName) |
51
|
|
|
{ |
52
|
22 |
|
$services = $this->findAndSortTaggedServices($tagName, $container); |
53
|
|
|
|
54
|
22 |
|
$definition = $container->getDefinition($destination[0]); |
55
|
|
|
|
56
|
22 |
|
$argument = $definition->getArgument($destination[1]); |
57
|
22 |
|
if ($argument === []) { |
58
|
22 |
|
$definition->replaceArgument($destination[1], $services); |
59
|
|
|
} |
60
|
22 |
|
} |
61
|
|
|
} |
62
|
|
|
|