|
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\TestProviderInterface; |
|
20
|
|
|
use Yarhon\RouteGuardBundle\Security\TestResolver\TestResolverInterface; |
|
21
|
|
|
use Yarhon\RouteGuardBundle\Controller\ArgumentResolver\ArgumentValueResolverInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class YarhonRouteGuardExtension extends Extension |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function load(array $configs, ContainerBuilder $container) |
|
32
|
|
|
{ |
|
33
|
2 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
34
|
2 |
|
$loader->load('services.xml'); |
|
35
|
2 |
|
$loader->load('cache.xml'); |
|
36
|
|
|
|
|
37
|
2 |
|
$configuration = new Configuration(); |
|
38
|
2 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
39
|
|
|
|
|
40
|
2 |
|
$this->setConfigParameters($container, $config); |
|
41
|
2 |
|
$this->registerAutoConfiguration($container); |
|
42
|
2 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param ContainerBuilder $container |
|
46
|
|
|
* @param array $config |
|
47
|
|
|
*/ |
|
48
|
2 |
|
private function setConfigParameters(ContainerBuilder $container, array $config) |
|
49
|
|
|
{ |
|
50
|
2 |
|
$definition = $container->getDefinition(RouteCollectionDataCollector::class); |
|
51
|
2 |
|
$definition->replaceArgument(2, $config['data_collector']); |
|
52
|
|
|
|
|
53
|
2 |
|
$definition = $container->getDefinition(RoutingExtension::class); |
|
54
|
2 |
|
$definition->replaceArgument(0, $config['twig']); |
|
55
|
2 |
|
} |
|
56
|
|
|
|
|
57
|
2 |
|
private function registerAutoConfiguration(ContainerBuilder $container) |
|
58
|
|
|
{ |
|
59
|
2 |
|
$container->registerForAutoconfiguration(TestProviderInterface::class)->addTag('yarhon_route_guard.test_provider'); |
|
60
|
2 |
|
$container->registerForAutoconfiguration(TestResolverInterface::class)->addTag('yarhon_route_guard.test_resolver'); |
|
61
|
2 |
|
$container->registerForAutoconfiguration(ArgumentValueResolverInterface::class)->addTag('yarhon_route_guard.argument_value_resolver'); |
|
62
|
2 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|