Skip to content

Commit

Permalink
[feature] Register Runner aliases (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan authored Jun 9, 2022
1 parent 91d1c30 commit a2fb5d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion DependencyInjection/Compiler/GroupRunnersCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Liip\MonitorBundle\DependencyInjection\Compiler;

use Liip\MonitorBundle\Runner;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand Down Expand Up @@ -35,10 +36,12 @@ public function process(ContainerBuilder $container): void
$runners = [];
foreach ($groups as $group) {
$container->setDefinition('liip_monitor.runner_'.$group, clone $definition);
$container->registerAliasForArgument('liip_monitor.runner_'.$group, Runner::class, $group.'Runner');
$runners[] = 'liip_monitor.runner_'.$group;
}

$container->setAlias('liip_monitor.runner', 'liip_monitor.runner_'.$defaultGroup);
$container->setAlias(Runner::class, 'liip_monitor.runner');
$runner = $container->getAlias('liip_monitor.runner');
$runner->setPublic(true);

Expand All @@ -48,7 +51,7 @@ public function process(ContainerBuilder $container): void
private function getGroups(array $services): array
{
$groups = [];
foreach ($services as $serviceId => $tags) {
foreach ($services as $tags) {
foreach ($tags as $attributes) {
if (!empty($attributes['group'])) {
$groups[$attributes['group']] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Liip\MonitorBundle\Tests\DependencyInjection\Compiler;

use Liip\MonitorBundle\DependencyInjection\Compiler\GroupRunnersCompilerPass;
use Liip\MonitorBundle\Runner;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -35,6 +36,12 @@ public function testProcess(): void
$this->assertContainerBuilderHasService('liip_monitor.runner_foobar');
$this->assertContainerBuilderHasService('liip_monitor.runner_bar');
$this->assertContainerBuilderHasService('liip_monitor.runner_baz');
$this->assertContainerBuilderHasAlias(Runner::class.' $fooRunner', 'liip_monitor.runner_foo');
$this->assertContainerBuilderHasAlias(Runner::class.' $foobarRunner', 'liip_monitor.runner_foobar');
$this->assertContainerBuilderHasAlias(Runner::class.' $barRunner', 'liip_monitor.runner_bar');
$this->assertContainerBuilderHasAlias(Runner::class.' $bazRunner', 'liip_monitor.runner_baz');
$this->assertContainerBuilderHasAlias(Runner::class.' $groupeParDéfautRunner', 'liip_monitor.runner_'.$defaultGroup);
$this->assertContainerBuilderHasAlias(Runner::class, 'liip_monitor.runner');
}

protected function registerCompilerPass(ContainerBuilder $container): void
Expand Down

0 comments on commit a2fb5d8

Please sign in to comment.