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

Skip to content

Hide definitions bearing the container.excluded tag #50452

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
if ($service instanceof Alias) {
$data['aliases'][$serviceId] = $this->getContainerAliasData($service);
} elseif ($service instanceof Definition) {
if ($service->hasTag('container.excluded')) {
continue;
}
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments, $builder, $serviceId);
} else {
$data['services'][$serviceId] = $service::class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
if ($service instanceof Alias) {
$services['aliases'][$serviceId] = $service;
} elseif ($service instanceof Definition) {
if ($service->hasTag('container.excluded')) {
continue;
}
$services['definitions'][$serviceId] = $service;
} else {
$services['services'][$serviceId] = $service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
}

if ($definition instanceof Definition) {
if ($definition->hasTag('container.excluded')) {
unset($serviceIds[$key]);
continue;
}
if ($showTag) {
$tags = $definition->getTag($showTag);
foreach ($tags as $tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ private function getContainerServicesDocument(ContainerBuilder $builder, string
continue;
}

if ($service instanceof Definition) {
if ($service->hasTag('container.excluded')) {
continue;
}
}

$serviceXML = $this->getContainerServiceDocument($service, $serviceId, null, $showArguments);
$containerXML->appendChild($containerXML->ownerDocument->importNode($serviceXML->childNodes->item(0), true));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;

/**
* @author Maksim Vorozhtsov <[email protected]>
*/
class ContainerExcluded
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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

Expand Down Expand Up @@ -85,6 +86,19 @@ public function testDeprecatedServiceAndAlias()
$this->assertStringContainsString('[WARNING] The "deprecated_alias" alias is deprecated since foo/bar 1.9 and will be removed in 2.0', $tester->getDisplay());
}

public function testExcludedService()
{
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);

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

$tester = new ApplicationTester($application);

$tester->run(['command' => 'debug:container']);
$this->assertStringNotContainsString(ContainerExcluded::class, $tester->getDisplay());
}

/**
* @dataProvider provideIgnoreBackslashWhenFindingService
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ services:
- '%env(REAL)%'
- '%env(int:key:2:json:JSON)%'
- '%env(float:key:2:json:JSON)%'
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ContainerExcluded:
tags: ['container.excluded']