Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Ignore backslashes in service ids when using debug:container and debug:autowiring#28487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionssrc/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ CHANGELOG
* Added new "auto" mode for `framework.session.cookie_secure` to turn it on when HTTPS is used
* Removed the `framework.messenger.encoder` and `framework.messenger.decoder` options. Use the `framework.messenger.serializer.id` option to replace the Messenger serializer.
* Deprecated the `ContainerAwareCommand` class in favor of `Symfony\Component\Console\Command\Command`
* Made `debug:container` and `debug:autowiring` ignore backslashes in service ids

4.1.0
-----
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -219,23 +219,27 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
throw new InvalidArgumentException(sprintf('No services found that match "%s".', $name));
}

$default = 1 === \count($matchingServices) ? $matchingServices[0] : null;
if (1 === \count($matchingServices)) {
return $matchingServices[0];
}

return $io->choice('Select one of the following services to display its information', $matchingServices, $default);
return $io->choice('Select one of the following services to display its information', $matchingServices);
}

private function findServiceIdsContaining(ContainerBuilder $builder, $name)
{
$serviceIds = $builder->getServiceIds();
$foundServiceIds = array();
$foundServiceIds =$foundServiceIdsIgnoringBackslashes =array();
foreach ($serviceIds as $serviceId) {
if (false === stripos($serviceId, $name)) {
continue;
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
$foundServiceIdsIgnoringBackslashes[] = $serviceId;
}
if (false !== stripos($serviceId, $name)) {
$foundServiceIds[] = $serviceId;
}
$foundServiceIds[] = $serviceId;
}

return $foundServiceIds;
return $foundServiceIds ?: $foundServiceIdsIgnoringBackslashes;
}

/**
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

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

if (empty($serviceIds)) {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;

class BackslashClass
{
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass;
use Symfony\Component\Console\Tester\ApplicationTester;

/**
Expand DownExpand Up@@ -63,4 +64,27 @@ public function testPrivateAlias()
$this->assertContains('public', $tester->getDisplay());
$this->assertContains('private_alias', $tester->getDisplay());
}

/**
* @dataProvider provideIgnoreBackslashWhenFindingService
*/
public function testIgnoreBackslashWhenFindingService(string $validServiceId)
{
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml'));

$application = new Application(static::$kernel);
$application->setAutoExit(false);

$tester = new ApplicationTester($application);
$tester->run(array('command' => 'debug:container', 'name' => $validServiceId));
$this->assertNotContains('No services found', $tester->getDisplay());
}

public function provideIgnoreBackslashWhenFindingService()
{
return array(
array(BackslashClass::class),
array('FixturesBackslashClass'),
);
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,18 @@ public function testSearchArgument()
$this->assertNotContains('Symfony\Component\Routing\RouterInterface', $tester->getDisplay());
}

public function testSearchIgnoreBackslashWhenFindingService()
{
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml'));

$application = new Application(static::$kernel);
$application->setAutoExit(false);

$tester = new ApplicationTester($application);
$tester->run(array('command' => 'debug:autowiring', 'search' => 'HttpKernelHttpKernelInterface'));
$this->assertContains('Symfony\Component\HttpKernel\HttpKernelInterface', $tester->getDisplay());
}

public function testSearchNoResults()
{
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml'));
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,3 +8,5 @@ services:
private_alias:
alias: public
public: false
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass:
class: Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass

[8]ページ先頭

©2009-2025 Movatter.jp