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