1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* GpsLab component. |
4
|
|
|
* |
5
|
|
|
* @author Peter Gribanov <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2016, Peter Gribanov |
7
|
|
|
* @license http://opensource.org/licenses/MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace GpsLab\Bundle\DomainEvent\DependencyInjection; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Config\FileLocator; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
15
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
16
|
|
|
|
17
|
|
|
class GpsLabDomainEventExtension extends Extension |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param array $configs |
21
|
|
|
* @param ContainerBuilder $container |
22
|
|
|
*/ |
23
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
24
|
|
|
{ |
25
|
4 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
26
|
4 |
|
$loader->load('queue.yml'); |
27
|
4 |
|
$loader->load('bus.yml'); |
28
|
4 |
|
$loader->load('locator.yml'); |
29
|
4 |
|
$loader->load('publisher.yml'); |
30
|
|
|
|
31
|
4 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
32
|
|
|
|
33
|
4 |
|
$container->setAlias('domain_event.bus', $this->busRealName($config['bus'])); |
34
|
4 |
|
$container->setAlias('domain_event.queue', $this->queueRealName($config['queue'])); |
35
|
4 |
|
$container->setAlias('domain_event.locator', $this->locatorRealName($config['locator'])); |
36
|
|
|
|
37
|
4 |
|
$container->getDefinition('domain_event.publisher')->replaceArgument(1, $config['publish_on_flush']); |
38
|
4 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $name |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
4 |
|
private function busRealName($name) |
46
|
|
|
{ |
47
|
4 |
|
if (in_array($name, ['listener_located', 'queue'])) { |
48
|
3 |
|
return 'domain_event.bus.'.$name; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
return $name; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $name |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
4 |
|
private function queueRealName($name) |
60
|
|
|
{ |
61
|
4 |
|
if (in_array($name, ['pull_memory', 'subscribe_executing'])) { |
62
|
3 |
|
return 'domain_event.queue.'.$name; |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
return $name; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $name |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
4 |
|
private function locatorRealName($name) |
74
|
|
|
{ |
75
|
4 |
|
if (in_array($name, ['direct_binding', 'container', 'symfony'])) { |
76
|
3 |
|
return 'domain_event.locator.'.$name; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
return $name; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
1 |
|
public function getAlias() |
86
|
|
|
{ |
87
|
1 |
|
return 'gpslab_domain_event'; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|