1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EmanueleMinotto\DomainParserBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* {@inheritdoc} |
13
|
|
|
*/ |
14
|
|
|
class DomainParserExtension extends Extension |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
39 |
|
public function load(array $configs, ContainerBuilder $container) |
20
|
|
|
{ |
21
|
39 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
22
|
|
|
|
23
|
39 |
|
$loader = new Loader\XmlFileLoader( |
24
|
39 |
|
$container, |
25
|
39 |
|
new FileLocator(__DIR__.'/../Resources/config') |
26
|
39 |
|
); |
27
|
39 |
|
$loader->load('services.xml'); |
28
|
|
|
|
29
|
39 |
|
$this->setCacheDir($config['cache_dir'], $container); |
30
|
39 |
|
$this->setHttpAdapter($config['http_adapter'], $container); |
31
|
39 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Set cache directory. |
35
|
|
|
* |
36
|
|
|
* @param string $cacheDir |
37
|
|
|
* @param ContainerBuilder $container |
38
|
|
|
*/ |
39
|
39 |
|
private function setCacheDir($cacheDir, ContainerBuilder $container) |
40
|
|
|
{ |
41
|
39 |
|
if (!$cacheDir) { |
42
|
36 |
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$container |
46
|
3 |
|
->getDefinition('pdp.public_suffix_list_manager') |
47
|
3 |
|
->replaceArgument(0, $cacheDir); |
48
|
3 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Set HTTP adapter. |
52
|
|
|
* |
53
|
|
|
* @param string $httpAdapter |
54
|
|
|
* @param ContainerBuilder $container |
55
|
|
|
*/ |
56
|
39 |
|
private function setHttpAdapter($httpAdapter, ContainerBuilder $container) |
57
|
|
|
{ |
58
|
39 |
|
if (!$httpAdapter) { |
59
|
39 |
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$container |
63
|
|
|
->getDefinition('pdp.public_suffix_list_manager') |
64
|
|
|
->addMethodCall('setHttpAdapter', [new Reference($httpAdapter)]); |
65
|
|
|
$container |
66
|
|
|
->getDefinition('domain_parser_bundle.cached_domains_list_warmer') |
67
|
|
|
->replaceArgument(0, new Reference($httpAdapter)); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|