|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace League\Tactician\Bundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use League\Tactician\Bundle\Security\Voter\HandleCommandVoter; |
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
11
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
|
12
|
|
|
|
|
13
|
|
|
class TacticianExtension extends ConfigurableExtension |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Configures the passed container according to the merged configuration. |
|
17
|
|
|
* |
|
18
|
|
|
* @param array $mergedConfig |
|
19
|
|
|
* @param ContainerBuilder $container |
|
20
|
|
|
*/ |
|
21
|
66 |
|
protected function loadInternal(array $mergedConfig, ContainerBuilder $container) |
|
22
|
|
|
{ |
|
23
|
66 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/services')); |
|
24
|
66 |
|
$loader->load('services.yml'); |
|
25
|
|
|
|
|
26
|
66 |
|
$this->configureSecurity($mergedConfig, $container); |
|
27
|
66 |
|
} |
|
28
|
|
|
|
|
29
|
69 |
|
public function getAlias() |
|
30
|
|
|
{ |
|
31
|
69 |
|
return 'tactician'; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Configure the security voter if the security middleware is loaded. |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $mergedConfig |
|
38
|
|
|
* @param ContainerBuilder $container |
|
39
|
|
|
*/ |
|
40
|
66 |
|
private function configureSecurity(array $mergedConfig, ContainerBuilder $container) |
|
41
|
|
|
{ |
|
42
|
66 |
|
foreach ($mergedConfig['commandbus'] as $commandBusConfig) { |
|
43
|
66 |
|
if (in_array('tactician.middleware.security', $commandBusConfig['middleware'])) { |
|
44
|
66 |
|
return $this->configureCommandSecurityVoter($mergedConfig, $container); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
42 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Configure the security voter. |
|
51
|
|
|
* |
|
52
|
|
|
* @param array $mergedConfig |
|
53
|
|
|
* @param ContainerBuilder $container |
|
54
|
|
|
*/ |
|
55
|
24 |
|
private function configureCommandSecurityVoter(array $mergedConfig, ContainerBuilder $container) |
|
56
|
|
|
{ |
|
57
|
24 |
|
if (!$container->has('tactician.middleware.security_voter')) { |
|
58
|
24 |
|
$definition = new Definition( |
|
59
|
24 |
|
HandleCommandVoter::class, |
|
60
|
|
|
[ |
|
61
|
24 |
|
new Reference('security.access.decision_manager'), |
|
62
|
24 |
|
$mergedConfig['security'] |
|
63
|
|
|
] |
|
64
|
|
|
); |
|
65
|
24 |
|
$definition->addTag('security.voter'); |
|
66
|
24 |
|
$container->setDefinition('tactician.middleware.security_voter', $definition); |
|
67
|
|
|
} |
|
68
|
24 |
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|