|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Debril\RssAtomBundle\DependencyInjection\CompilerPass; |
|
4
|
|
|
|
|
5
|
|
|
use Debril\RssAtomBundle\DependencyInjection\Configuration; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class DriverCompilerPass |
|
13
|
|
|
*/ |
|
14
|
|
|
class DriverCompilerPass implements CompilerPassInterface |
|
15
|
|
|
{ |
|
16
|
|
|
public function process(ContainerBuilder $container) |
|
17
|
|
|
{ |
|
18
|
|
|
$configs = $container->getExtensionConfig('debril_rss_atom'); |
|
19
|
|
|
|
|
20
|
|
|
$configTree = new Configuration(); |
|
21
|
|
|
$processor = new Processor(); |
|
22
|
|
|
$config = $processor->processConfiguration($configTree, $configs); |
|
23
|
|
|
|
|
24
|
|
|
switch ($config['driver']) { |
|
25
|
|
|
case 'curl': |
|
26
|
|
|
// nothing to do |
|
27
|
|
|
break; |
|
28
|
|
|
case 'file': |
|
29
|
|
|
$container |
|
30
|
|
|
->getDefinition('debril.reader') |
|
31
|
|
|
->replaceArgument(0, new Reference('debril.file')); |
|
32
|
|
|
|
|
33
|
|
|
break; |
|
34
|
|
|
case 'guzzle': |
|
35
|
|
|
if (! isset($config['driver_service'])) { |
|
36
|
|
|
throw new \Exception('When setting debril_rss_atom.driver to "guzzle", you should provide Client service ID in debril_rss_atom.driver_service!'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$guzzlebridge = $container->getDefinition('debril.http.guzzle_bridge'); |
|
40
|
|
|
$guzzlebridge->addArgument(new Reference($config['driver_service'])); |
|
41
|
|
|
|
|
42
|
|
|
$container |
|
43
|
|
|
->getDefinition('debril.reader') |
|
44
|
|
|
->replaceArgument(0, $guzzlebridge); |
|
45
|
|
|
break; |
|
46
|
|
|
case 'service': |
|
47
|
|
|
if (! isset($config['driver_service'])) { |
|
48
|
|
|
throw new \Exception('When setting debril_rss_atom.driver to "service", you should provide service ID in debril_rss_atom.driver_service!'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$container |
|
52
|
|
|
->getDefinition('debril.reader') |
|
53
|
|
|
->replaceArgument(0, new Reference($config['driver_service'])); |
|
54
|
|
|
break; |
|
55
|
|
|
default: |
|
56
|
|
|
throw new \Exception('Unable to handle debril_rss_atom.driver value!'); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|