|
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
|
|
|
$root |
|
|
|
|
|
|
36
|
5 |
|
->scalarNode('bus') |
|
37
|
|
|
->cannotBeEmpty() |
|
38
|
|
|
->defaultValue('listener_located') |
|
39
|
|
|
->end() |
|
40
|
|
|
->scalarNode('queue') |
|
41
|
|
|
->cannotBeEmpty() |
|
42
|
|
|
->defaultValue('pull_memory') |
|
43
|
|
|
->end() |
|
44
|
|
|
->scalarNode('locator') |
|
45
|
|
|
->cannotBeEmpty() |
|
46
|
|
|
->defaultValue('symfony') |
|
47
|
|
|
->end() |
|
48
|
|
|
->booleanNode('publish_on_flush') |
|
49
|
|
|
->defaultValue(false) |
|
50
|
|
|
->end() |
|
51
|
|
|
; |
|
52
|
|
|
|
|
53
|
|
|
return $tree_builder; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $name |
|
58
|
|
|
* |
|
59
|
|
|
* @return TreeBuilder |
|
60
|
|
|
*/ |
|
61
|
5 |
|
private function createTreeBuilder($name) |
|
62
|
|
|
{ |
|
63
|
|
|
// Symfony 4.2 + |
|
64
|
5 |
|
if (method_exists(TreeBuilder::class, '__construct')) { |
|
65
|
5 |
|
return new TreeBuilder($name); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
// Symfony 4.1 and below |
|
69
|
|
|
return new TreeBuilder(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param TreeBuilder $tree_builder |
|
74
|
|
|
* @param string $name |
|
75
|
|
|
* |
|
76
|
|
|
* @return ArrayNodeDefinition |
|
77
|
|
|
*/ |
|
78
|
5 |
|
private function getRootNode(TreeBuilder $tree_builder, $name) |
|
79
|
|
|
{ |
|
80
|
5 |
|
if (method_exists($tree_builder, 'getRootNode')) { |
|
81
|
|
|
// Symfony 4.2 + |
|
82
|
5 |
|
$root = $tree_builder->getRootNode(); |
|
83
|
|
|
} else { |
|
84
|
|
|
// Symfony 4.1 and below |
|
85
|
|
|
$root = $tree_builder->root($name); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// @codeCoverageIgnoreStart |
|
89
|
|
|
if (!($root instanceof ArrayNodeDefinition)) { // should be always false |
|
90
|
|
|
throw new \RuntimeException(sprintf('The root node should be instance of %s, got %s instead.', ArrayNodeDefinition::class, get_class($root))); |
|
91
|
|
|
} |
|
92
|
|
|
// @codeCoverageIgnoreEnd |
|
93
|
|
|
|
|
94
|
5 |
|
return $root; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.