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; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
16
|
|
|
use Symfony\Component\Config\FileLocator; |
17
|
|
|
use Yarhon\RouteGuardBundle\Cache\DataCollector\RouteCollectionDataCollector; |
18
|
|
|
use Yarhon\RouteGuardBundle\Twig\Extension\RoutingExtension; |
19
|
|
|
use Yarhon\RouteGuardBundle\Security\TestProvider\ProviderInterface; |
20
|
|
|
use Yarhon\RouteGuardBundle\Security\TestResolver\SymfonySecurityResolverInterface; |
21
|
|
|
use Yarhon\RouteGuardBundle\Controller\ArgumentResolver\ArgumentValueResolverInterface; |
22
|
|
|
use Yarhon\RouteGuardBundle\Security\AuthorizationChecker\AuthorizationCheckerInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class YarhonRouteGuardExtension extends Extension |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
26 |
|
public function load(array $configs, ContainerBuilder $container) |
33
|
|
|
{ |
34
|
26 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
35
|
26 |
|
$loader->load('cache.xml'); |
36
|
26 |
|
$loader->load('routing.xml'); |
37
|
26 |
|
$loader->load('controller.xml'); |
38
|
26 |
|
$loader->load('security.xml'); |
39
|
26 |
|
$loader->load('twig.xml'); |
40
|
|
|
|
41
|
26 |
|
$configuration = new Configuration(); |
42
|
26 |
|
$config = $this->processConfiguration($configuration, $configs); |
43
|
|
|
|
44
|
26 |
|
$this->setConfigParameters($container, $config); |
45
|
26 |
|
$this->registerAutoConfiguration($container); |
46
|
26 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param ContainerBuilder $container |
50
|
|
|
* @param array $config |
51
|
|
|
*/ |
52
|
26 |
|
private function setConfigParameters(ContainerBuilder $container, array $config) |
53
|
|
|
{ |
54
|
26 |
|
$definition = $container->getDefinition(RouteCollectionDataCollector::class); |
55
|
26 |
|
$definition->replaceArgument(2, $config['data_collector']); |
56
|
|
|
|
57
|
26 |
|
$definition = $container->getDefinition(RoutingExtension::class); |
58
|
26 |
|
$definition->replaceArgument(0, $config['twig']); |
59
|
26 |
|
} |
60
|
|
|
|
61
|
26 |
|
private function registerAutoConfiguration(ContainerBuilder $container) |
62
|
|
|
{ |
63
|
26 |
|
$container->registerForAutoconfiguration(ProviderInterface::class)->addTag('yarhon_route_guard.test_provider'); |
64
|
26 |
|
$container->registerForAutoconfiguration(SymfonySecurityResolverInterface::class)->addTag('yarhon_route_guard.test_resolver.symfony_security'); |
65
|
26 |
|
$container->registerForAutoconfiguration(ArgumentValueResolverInterface::class)->addTag('yarhon_route_guard.argument_value_resolver'); |
66
|
26 |
|
$container->registerForAutoconfiguration(AuthorizationCheckerInterface::class)->addTag('yarhon_route_guard.authorization_checker'); |
67
|
26 |
|
} |
68
|
|
|
} |
69
|
|
|
|