-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathAddTopicMetaPass.php
65 lines (52 loc) · 1.5 KB
/
AddTopicMetaPass.php
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
<?php
namespace Enqueue\Bundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class AddTopicMetaPass implements CompilerPassInterface
{
/**
* @var array
*/
private $topicsMeta;
public function __construct()
{
$this->topicsMeta = [];
}
/**
* @param string $topicName
* @param string $topicDescription
* @param array $topicSubscribers
*
* @return $this
*/
public function add($topicName, $topicDescription = '', array $topicSubscribers = [])
{
$this->topicsMeta[$topicName] = [];
if ($topicDescription) {
$this->topicsMeta[$topicName]['description'] = $topicDescription;
}
if ($topicSubscribers) {
$this->topicsMeta[$topicName]['processors'] = $topicSubscribers;
}
return $this;
}
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$metaRegistryId = 'enqueue.client.meta.topic_meta_registry';
if (false == $container->hasDefinition($metaRegistryId)) {
return;
}
$metaRegistry = $container->getDefinition($metaRegistryId);
$metaRegistry->replaceArgument(0, array_merge_recursive($metaRegistry->getArgument(0), $this->topicsMeta));
}
/**
* @return static
*/
public static function create()
{
return new static();
}
}