for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace BrainExe\Core\DependencyInjection\CompilerPass;
use BrainExe\Core\Annotations\CompilerPass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
/**
* @CompilerPass(priority=9)
*/
class RedisCompilerPass implements CompilerPassInterface
{
* {@inheritdoc}
public function process(ContainerBuilder $container)
$redis = $container->findDefinition('Redis');
$masterArguments = $this->getArguments($container, '');
try {
$slaveArguments = $this->getArguments($container, '.slave');
$parameters = [$masterArguments, $slaveArguments];
$options = ['replication' => true];
$redis->setArguments([$parameters, $options]);
} catch (ParameterNotFoundException $e) {
// master only
$redis->setArguments([$masterArguments]);
}
* @param ContainerBuilder $container
* @param string $prefix
* @return string
protected function getArguments(ContainerBuilder $container, string $prefix) : string
return $container->getParameter("redis$prefix.connection");
sprintf
$prefix
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.
// Instead of $x = "foo $bar $baz"; // Better use either $x = "foo " . $bar . " " . $baz; $x = sprintf("foo %s %s", $bar, $baz);
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.