|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
8
|
|
|
use Symfony\Component\Config\FileLocator; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
10
|
|
|
|
|
11
|
|
|
class DtcQueueExtension extends Extension |
|
12
|
|
|
{ |
|
13
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
14
|
|
|
{ |
|
15
|
|
|
$processor = new Processor(); |
|
16
|
|
|
$configuration = new Configuration(); |
|
17
|
|
|
|
|
18
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
|
19
|
|
|
|
|
20
|
|
|
if (isset($config['beanstalkd'])) { |
|
21
|
|
|
if (!isset($config['beanstalkd']['host'])) { |
|
22
|
|
|
throw new \Exception('dtc_queue: beanstalkd requires host in config.yml'); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
if (isset($config['beanstalkd']['host'])) { |
|
27
|
|
|
$container->setParameter('dtc_queue.beanstalkd.host', $config['beanstalkd']['host']); |
|
28
|
|
|
} |
|
29
|
|
|
if (isset($config['beanstalkd']['tube'])) { |
|
30
|
|
|
$container->setParameter('dtc_queue.beanstalkd.tube', $config['beanstalkd']['tube']); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (isset($config['rabbit_mq'])) { |
|
34
|
|
|
foreach (['host', 'port', 'user', 'password'] as $value) { |
|
35
|
|
|
if (!isset($config['rabbit_mq'][$value])) { |
|
36
|
|
|
throw new \Exception('dtc_queue: rabbit_mq must have '.$value.' in config.yml'); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
$container->setParameter('dtc_queue.rabbit_mq', $config['rabbit_mq']); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$container->setParameter('dtc_queue.default_manager', $config['default_manager']); |
|
43
|
|
|
$container->setParameter('dtc_queue.document_manager', $config['document_manager']); |
|
44
|
|
|
$container->setParameter('dtc_queue.job_class', isset($config['class']) ? $config['class'] : null); |
|
45
|
|
|
|
|
46
|
|
|
// Load Grid if Dtc\GridBundle Bundle is registered |
|
47
|
|
|
$yamlLoader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
48
|
|
|
|
|
49
|
|
|
$yamlLoader->load('queue.yml'); |
|
50
|
|
|
$yamlLoader->load('grid.yml'); |
|
51
|
|
|
|
|
52
|
|
|
$odmManager = "doctrine_mongodb.odm.{$config['document_manager']}_document_manager"; |
|
53
|
|
|
$container->setAlias('dtc_queue.document_manager', $odmManager); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getAlias() |
|
57
|
|
|
{ |
|
58
|
|
|
return 'dtc_queue'; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|