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

Skip to content

Commit 20f37b3

Browse files
committed
[FrameworkBundle] Add the ability to ignore backslashes in service ids when using debug:container and debug:autowiring
1 parent 57c76a4 commit 20f37b3

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* Added new "auto" mode for `framework.session.cookie_secure` to turn it on when HTTPS is used
1414
* Removed the `framework.messenger.encoder` and `framework.messenger.decoder` options. Use the `framework.messenger.serializer.id` option to replace the Messenger serializer.
1515
* Deprecated the `ContainerAwareCommand` class in favor of `Symfony\Component\Console\Command\Command`
16+
* Add the ability to ignore backslashes in service ids when using `debug:container` and `debug:autowiring`
1617

1718
4.1.0
1819
-----

src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private function findServiceIdsContaining(ContainerBuilder $builder, $name)
229229
$serviceIds = $builder->getServiceIds();
230230
$foundServiceIds = array();
231231
foreach ($serviceIds as $serviceId) {
232-
if (false === stripos($serviceId, $name)) {
232+
if (false === stripos(str_replace('\\', '', $serviceId), $name)) {
233233
continue;
234234
}
235235
$foundServiceIds[] = $serviceId;

src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6666

6767
if ($search = $input->getArgument('search')) {
6868
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($search) {
69-
return false !== stripos($serviceId, $search);
69+
return false !== stripos(str_replace('\\', '', $serviceId), $search);
7070
});
7171

7272
if (empty($serviceIds)) {

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDebugCommandTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,27 @@ public function testPrivateAlias()
6363
$this->assertContains('public', $tester->getDisplay());
6464
$this->assertContains('private_alias', $tester->getDisplay());
6565
}
66+
67+
/**
68+
* @dataProvider getValidServiceIds
69+
*/
70+
public function testIgnoreBackslashWhenFindingService(string $validServiceId)
71+
{
72+
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml'));
73+
74+
$application = new Application(static::$kernel);
75+
$application->setAutoExit(false);
76+
77+
$tester = new ApplicationTester($application);
78+
$tester->run(array('command' => 'debug:container', 'name' => $validServiceId));
79+
$this->assertContains('Information for Service "logger"', $tester->getDisplay());
80+
}
81+
82+
public function getValidServiceIds()
83+
{
84+
return array(
85+
array('Psr\\Log\\LoggerInterface'),
86+
array('LogLoggerInterface'),
87+
);
88+
}
6689
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/DebugAutowiringCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ public function testSearchArgument()
4747
$this->assertNotContains('Symfony\Component\Routing\RouterInterface', $tester->getDisplay());
4848
}
4949

50+
public function testSearchIgnoreBackslashWhenFindingService()
51+
{
52+
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml'));
53+
54+
$application = new Application(static::$kernel);
55+
$application->setAutoExit(false);
56+
57+
$tester = new ApplicationTester($application);
58+
$tester->run(array('command' => 'debug:autowiring', 'search' => 'HttpKernelHttpKernelInterface'));
59+
$this->assertContains('Symfony\Component\HttpKernel\HttpKernelInterface', $tester->getDisplay());
60+
}
61+
5062
public function testSearchNoResults()
5163
{
5264
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml'));

0 commit comments

Comments
 (0)