-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackgroundQueueExtension.php
More file actions
66 lines (56 loc) · 2.08 KB
/
Copy pathBackgroundQueueExtension.php
File metadata and controls
66 lines (56 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace ADT\BackgroundQueueSymfony\Bundle\DependencyInjection;
use Exception;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
class BackgroundQueueExtension extends Extension
{
/**
* @throws Exception
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
foreach ($config['callbacks'] as &$_callback) {
$_callback[0] = $this->normalizeClass($_callback[0]);
}
if ($config['producer']) {
$config['producer'] = $this->normalizeClass($config['producer']);
$loader->load('broker.yml');
}
if ($config['logger']) {
$config['logger'] = $this->normalizeClass($config['logger']);
}
if ($config['onBeforeProcess']) {
$config['onBeforeProcess'][0] = $this->normalizeClass($config['onBeforeProcess'][0]);
}
if ($config['onError']) {
$config['onError'][0] = $this->normalizeClass($config['onError'][0]);
}
if ($config['onAfterProcess']) {
$config['onAfterProcess'][0] = $this->normalizeClass($config['onAfterProcess'][0]);
}
$definition = new Definition('ADT\BackgroundQueue\BackgroundQueue', [$config]);
$container->setDefinition('ADT\BackgroundQueue\BackgroundQueue', $definition);
$services = $container->findTaggedServiceIds('background-queue.command');
foreach ($services as $id => $tags) {
$definition = $container->getDefinition($id);
// Zavolejte metodu setLocksDir na každou službu
$definition->addMethodCall('setLocksDir', [$config['locksDir']]);
}
}
private function normalizeClass(string $class)
{
if ($class[0] === '@') {
$class = new Reference(substr($class, 1));
}
return $class;
}
}