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\Definition\Builder\ArrayNodeDefinition; |
13
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
14
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
15
|
|
|
|
16
|
|
|
class Configuration implements ConfigurationInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Config tree builder. |
20
|
|
|
* |
21
|
|
|
* Example config: |
22
|
|
|
* |
23
|
|
|
* gpslab_domain_event: |
24
|
|
|
* bus: 'listener_located' |
25
|
|
|
* queue: 'pull_memory' |
26
|
|
|
* locator: 'symfony' |
27
|
|
|
* |
28
|
|
|
* @return TreeBuilder |
29
|
|
|
*/ |
30
|
5 |
|
public function getConfigTreeBuilder() |
31
|
|
|
{ |
32
|
5 |
|
$tree_builder = $this->createTreeBuilder('gpslab_domain_event'); |
33
|
5 |
|
$root = $this->getRootNode($tree_builder, 'gpslab_domain_event'); |
34
|
|
|
|
35
|
5 |
|
$bus = $root->children()->scalarNode('bus'); |
36
|
5 |
|
$bus->cannotBeEmpty()->defaultValue('listener_located'); |
37
|
|
|
|
38
|
5 |
|
$queue = $root->children()->scalarNode('queue'); |
39
|
5 |
|
$queue->cannotBeEmpty()->defaultValue('pull_memory'); |
40
|
|
|
|
41
|
5 |
|
$locator = $root->children()->scalarNode('locator'); |
42
|
5 |
|
$locator->cannotBeEmpty()->defaultValue('symfony'); |
43
|
|
|
|
44
|
5 |
|
$publish_on_flush = $root->children()->booleanNode('publish_on_flush'); |
45
|
5 |
|
$publish_on_flush->defaultValue(false); |
46
|
|
|
|
47
|
5 |
|
return $tree_builder; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $name |
52
|
|
|
* |
53
|
|
|
* @return TreeBuilder |
54
|
|
|
*/ |
55
|
5 |
|
private function createTreeBuilder($name) |
56
|
|
|
{ |
57
|
|
|
// Symfony 4.2 + |
58
|
5 |
|
if (method_exists(TreeBuilder::class, '__construct')) { |
59
|
5 |
|
return new TreeBuilder($name); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// Symfony 4.1 and below |
63
|
|
|
return new TreeBuilder(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param TreeBuilder $tree_builder |
68
|
|
|
* @param string $name |
69
|
|
|
* |
70
|
|
|
* @return ArrayNodeDefinition |
71
|
|
|
*/ |
72
|
5 |
|
private function getRootNode(TreeBuilder $tree_builder, $name) |
73
|
|
|
{ |
74
|
5 |
|
if (method_exists($tree_builder, 'getRootNode')) { |
75
|
|
|
// Symfony 4.2 + |
76
|
5 |
|
$root = $tree_builder->getRootNode(); |
77
|
|
|
} else { |
78
|
|
|
// Symfony 4.1 and below |
79
|
|
|
$root = $tree_builder->root($name); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// @codeCoverageIgnoreStart |
83
|
|
|
if (!($root instanceof ArrayNodeDefinition)) { // should be always false |
84
|
|
|
throw new \RuntimeException(sprintf('The root node should be instance of %s, got %s instead.', ArrayNodeDefinition::class, get_class($root))); |
85
|
|
|
} |
86
|
|
|
// @codeCoverageIgnoreEnd |
87
|
|
|
|
88
|
5 |
|
return $root; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.