Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c1b384

Browse files
committed
Avoid reflection-based registration for command public services
1 parent f8133cb commit 6c1b384

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testProcess($public)
5353
}
5454

5555
$this->assertTrue($container->hasParameter('console.command.ids'));
56-
$this->assertSame(array($id), $container->getParameter('console.command.ids'));
56+
$this->assertSame(array($alias => $id), $container->getParameter('console.command.ids'));
5757
}
5858

5959
public function visibilityProvider()

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ public function process(ContainerBuilder $container)
3939
throw new InvalidArgumentException(sprintf('The service "%s" tagged "console.command" must be a subclass of "%s".', $id, Command::class));
4040
}
4141

42+
$commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
43+
if ($container->hasAlias($commandId) || isset($serviceIds[$commandId])) {
44+
$commandId = $commandId.'_'.$id;
45+
}
4246
if (!$definition->isPublic()) {
43-
$serviceId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
44-
if ($container->hasAlias($serviceId)) {
45-
$serviceId = $serviceId.'_'.$id;
46-
}
47-
$container->setAlias($serviceId, $id);
48-
$id = $serviceId;
47+
$container->setAlias($commandId, $id);
48+
$id = $commandId;
4949
}
5050

51-
$serviceIds[] = $id;
51+
$serviceIds[$commandId] = $id;
5252
}
5353

5454
$container->setParameter('console.command.ids', $serviceIds);

src/Symfony/Component/Console/Tests/DependencyInjection/AddConsoleCommandPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testProcess($public)
5050
}
5151

5252
$this->assertTrue($container->hasParameter('console.command.ids'));
53-
$this->assertSame(array($id), $container->getParameter('console.command.ids'));
53+
$this->assertSame(array($alias => $id), $container->getParameter('console.command.ids'));
5454
}
5555

5656
public function visibilityProvider()

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ public function registerCommands(Application $application)
183183
}
184184
$class = $ns.'\\'.$file->getBasename('.php');
185185
if ($this->container) {
186+
$commandIds = $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : array();
186187
$alias = 'console.command.'.strtolower(str_replace('\\', '_', $class));
187-
if ($this->container->has($alias)) {
188+
if (isset($commandIds[$alias]) || $this->container->has($alias)) {
188189
continue;
189190
}
190191
}

0 commit comments

Comments
 (0)