1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
6
|
|
|
use Symfony\Component\Config\Definition\Processor; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
9
|
|
|
use Symfony\Component\Config\FileLocator; |
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
11
|
|
|
|
12
|
|
|
class DtcQueueExtension extends Extension |
13
|
|
|
{ |
14
|
|
|
public function load(array $configs, ContainerBuilder $container) |
15
|
|
|
{ |
16
|
|
|
$processor = new Processor(); |
17
|
|
|
$configuration = new Configuration(); |
18
|
|
|
|
19
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
20
|
|
|
$this->configBeanstalkd($config, $container); |
21
|
|
|
$this->configRabbitMQ($config, $container); |
22
|
|
|
|
23
|
|
|
$container->setParameter('dtc_queue.default_manager', $config['default_manager']); |
24
|
|
|
$container->setParameter('dtc_queue.document_manager', $config['document_manager']); |
25
|
|
|
$container->setParameter('dtc_queue.entity_manager', $config['entity_manager']); |
26
|
|
|
$container->setParameter('dtc_queue.run_manager', isset($config['run_manager']) ? $config['run_manager'] : $config['default_manager']); |
27
|
|
|
$container->setParameter('dtc_queue.priority_max', $config['priority_max']); |
28
|
|
|
$container->setParameter('dtc_queue.priority_direction', $config['priority_direction']); |
29
|
|
|
$this->configClasses($config, $container); |
30
|
|
|
$this->configAdmin($config, $container); |
31
|
|
|
|
32
|
|
|
// Load Grid if Dtc\GridBundle Bundle is registered |
33
|
|
|
$yamlLoader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
34
|
|
|
|
35
|
|
|
$yamlLoader->load('queue.yml'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function configAdmin(array $config, ContainerBuilder $container) |
39
|
|
|
{ |
40
|
|
|
$container->setParameter('dtc_queue.admin.chartjs', $config['admin']['chartjs']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function configClasses(array $config, ContainerBuilder $container) |
44
|
|
|
{ |
45
|
|
|
$container->setParameter('dtc_queue.class_job', isset($config['class_job']) ? $config['class_job'] : null); |
46
|
|
|
$container->setParameter('dtc_queue.class_job_archive', isset($config['class_job_archive']) ? $config['class_job_archive'] : null); |
47
|
|
|
$container->setParameter('dtc_queue.class_run', isset($config['class_run']) ? $config['class_run'] : null); |
48
|
|
|
$container->setParameter('dtc_queue.class_run_archive', isset($config['class_run_archive']) ? $config['class_run_archive'] : null); |
49
|
|
|
$container->setParameter('dtc_queue.class_job_timing', isset($config['class_job_timing']) ? $config['class_job_timing'] : null); |
50
|
|
|
$container->setParameter('dtc_queue.record_timings', isset($config['record_timings']) ? $config['record_timings'] : false); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function configRabbitMQ(array $config, ContainerBuilder $container) |
54
|
|
|
{ |
55
|
|
|
if (isset($config['rabbit_mq'])) { |
56
|
|
|
foreach (['host', 'port', 'user', 'password'] as $value) { |
57
|
|
|
if (!isset($config['rabbit_mq'][$value])) { |
58
|
|
|
throw new InvalidConfigurationException('dtc_queue: rabbit_mq must have '.$value.' in config.yml'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
$config['rabbit_mq']['queue_args']['max_priority'] = $config['priority_max']; |
62
|
|
|
$container->setParameter('dtc_queue.rabbit_mq', $config['rabbit_mq']); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function configBeanstalkd(array $config, ContainerBuilder $container) |
67
|
|
|
{ |
68
|
|
|
if (isset($config['beanstalkd'])) { |
69
|
|
|
if (!isset($config['beanstalkd']['host'])) { |
70
|
|
|
throw new InvalidConfigurationException('dtc_queue: beanstalkd requires host in config.yml'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (isset($config['beanstalkd']['host'])) { |
75
|
|
|
$container->setParameter('dtc_queue.beanstalkd.host', $config['beanstalkd']['host']); |
76
|
|
|
} |
77
|
|
|
if (isset($config['beanstalkd']['tube'])) { |
78
|
|
|
$container->setParameter('dtc_queue.beanstalkd.tube', $config['beanstalkd']['tube']); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getAlias() |
83
|
|
|
{ |
84
|
|
|
return 'dtc_queue'; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|