1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License (MIT) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2015 Spomky-Labs |
7
|
|
|
* |
8
|
|
|
* This software may be modified and distributed under the terms |
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace SpomkyLabs\IpFilterBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Processor; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
19
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
20
|
|
|
|
21
|
|
|
class SpomkyIpFilterExtension extends Extension |
22
|
|
|
{ |
23
|
|
|
private $alias; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $alias |
27
|
|
|
*/ |
28
|
|
|
public function __construct($alias) |
29
|
|
|
{ |
30
|
|
|
$this->alias = $alias; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function load(array $configs, ContainerBuilder $container) |
34
|
|
|
{ |
35
|
|
|
$processor = new Processor(); |
36
|
|
|
$configuration = new Configuration($this->getAlias()); |
37
|
|
|
|
38
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
39
|
|
|
|
40
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
41
|
|
|
if ('2.4' > Kernel::VERSION) { |
42
|
|
|
$loader->load('service_2.3.xml'); |
43
|
|
|
} else { |
44
|
|
|
$loader->load('service.xml'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$container->setAlias($this->getAlias().'.ip_manager', $config['ip_manager']); |
48
|
|
|
$container->setParameter($this->getAlias().'.ip.class', $config['ip_class']); |
49
|
|
|
|
50
|
|
|
$container->setAlias($this->getAlias().'.range_manager', $config['range_manager']); |
51
|
|
|
$container->setParameter($this->getAlias().'.range.class', $config['range_class']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getAlias() |
58
|
|
|
{ |
59
|
|
|
return $this->alias; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|