1 | <?php |
||
13 | class RedisCompilerPass implements CompilerPassInterface |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | 3 | public function process(ContainerBuilder $container) |
|
20 | { |
||
21 | 3 | $redis = $container->getDefinition('redis'); |
|
22 | |||
23 | 3 | $masterArguments = $this->getArguments($container, ''); |
|
24 | |||
25 | try { |
||
26 | 3 | $slaveArguments = $this->getArguments($container, '.slave'); |
|
27 | $parameters = [$masterArguments, $slaveArguments]; |
||
28 | $options = ['replication' => true]; |
||
29 | |||
30 | $redis->setArguments([$parameters, $options]); |
||
31 | 3 | } catch (ParameterNotFoundException $e) { |
|
32 | // master only |
||
33 | 3 | $redis->setArguments([$masterArguments]); |
|
34 | } |
||
35 | 3 | } |
|
36 | |||
37 | /** |
||
38 | * @param ContainerBuilder $container |
||
39 | * @param string $prefix |
||
40 | * @return string |
||
41 | */ |
||
42 | 3 | protected function getArguments(ContainerBuilder $container, string $prefix) : string |
|
46 | } |
||
47 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.