|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MediaMonks\CrawlerBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This is the class that loads and manages your bundle configuration. |
|
14
|
|
|
* |
|
15
|
|
|
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html |
|
16
|
|
|
*/ |
|
17
|
|
|
class MediaMonksCrawlerExtension extends Extension implements ExtensionInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
2 |
|
public function load(array $configs, ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
2 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
|
25
|
|
|
|
|
26
|
2 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
27
|
2 |
|
$loader->load('services.xml'); |
|
28
|
|
|
|
|
29
|
2 |
|
$this->loadCrawler($container, $config); |
|
30
|
2 |
|
$this->loadClientPrerender($container, $config); |
|
31
|
2 |
|
$this->loadClientPrerenderIo($container, $config); |
|
32
|
2 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param ContainerBuilder $container |
|
36
|
|
|
* @param array $config |
|
37
|
|
|
*/ |
|
38
|
2 |
|
protected function loadCrawler(ContainerBuilder $container, array $config) |
|
39
|
|
|
{ |
|
40
|
2 |
|
if (!$container->has($config['client'])) { |
|
41
|
2 |
|
$config['client'] = 'mediamonks_crawler.client.'.$config['client']; |
|
42
|
2 |
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
$container->getDefinition('mediamonks_crawler.crawler') |
|
45
|
2 |
|
->replaceArgument(0, new Reference($config['client'])) |
|
46
|
2 |
|
->addMethodCall('setLimit', [$config['limit']]) |
|
47
|
2 |
|
->addMethodCall('setStopOnError', [$config['stop_on_error']]) |
|
48
|
2 |
|
->addMethodCall('setExceptionOnError', [$config['exception_on_error']]); |
|
49
|
2 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param ContainerBuilder $container |
|
53
|
|
|
* @param array $config |
|
54
|
|
|
*/ |
|
55
|
2 |
|
protected function loadClientPrerender(ContainerBuilder $container, array $config) |
|
56
|
|
|
{ |
|
57
|
2 |
|
$container->getDefinition('mediamonks_crawler.client.prerender') |
|
58
|
2 |
|
->replaceArgument(0, $config['prerender']['url']); |
|
59
|
2 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param ContainerBuilder $container |
|
63
|
|
|
* @param array $config |
|
64
|
|
|
*/ |
|
65
|
2 |
|
protected function loadClientPrerenderIo(ContainerBuilder $container, array $config) |
|
66
|
|
|
{ |
|
67
|
2 |
|
$container->getDefinition('mediamonks_crawler.client.prerender_io') |
|
68
|
2 |
|
->replaceArgument(0, $config['prerender_io']['token']); |
|
69
|
2 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function getAlias() |
|
75
|
|
|
{ |
|
76
|
2 |
|
return 'mediamonks_crawler'; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|