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

Skip to content

Commit 2c668ba

Browse files
Myks92chalasr
authored andcommitted
Ignore definitions bearing the container.excluded tag
1 parent 4b72b61 commit 2c668ba

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
106106
if ($service instanceof Alias) {
107107
$data['aliases'][$serviceId] = $this->getContainerAliasData($service);
108108
} elseif ($service instanceof Definition) {
109+
if ($service->hasTag('container.excluded')) {
110+
continue;
111+
}
109112
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments, $builder, $serviceId);
110113
} else {
111114
$data['services'][$serviceId] = $service::class;

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
162162
if ($service instanceof Alias) {
163163
$services['aliases'][$serviceId] = $service;
164164
} elseif ($service instanceof Definition) {
165+
if ($service->hasTag('container.excluded')) {
166+
continue;
167+
}
165168
$services['definitions'][$serviceId] = $service;
166169
} else {
167170
$services['services'][$serviceId] = $service;

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

+4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
198198
}
199199

200200
if ($definition instanceof Definition) {
201+
if ($definition->hasTag('container.excluded')) {
202+
unset($serviceIds[$key]);
203+
continue;
204+
}
201205
if ($showTag) {
202206
$tags = $definition->getTag($showTag);
203207
foreach ($tags as $tag) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

+6
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ private function getContainerServicesDocument(ContainerBuilder $builder, string
294294
continue;
295295
}
296296

297+
if ($service instanceof Definition) {
298+
if ($service->hasTag('container.excluded')) {
299+
continue;
300+
}
301+
}
302+
297303
$serviceXML = $this->getContainerServiceDocument($service, $serviceId, null, $showArguments);
298304
$containerXML->appendChild($containerXML->ownerDocument->importNode($serviceXML->childNodes->item(0), true));
299305
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;
6+
7+
/**
8+
* @author Maksim Vorozhtsov <[email protected]>
9+
*/
10+
class ContainerExcluded
11+
{
12+
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Application;
1515
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass;
16+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ContainerExcluded;
1617
use Symfony\Component\Console\Tester\ApplicationTester;
1718
use Symfony\Component\Console\Tester\CommandCompletionTester;
1819

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

89+
public function testExcludedService()
90+
{
91+
static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml']);
92+
93+
$application = new Application(static::$kernel);
94+
$application->setAutoExit(false);
95+
96+
$tester = new ApplicationTester($application);
97+
98+
$tester->run(['command' => 'debug:container']);
99+
$this->assertStringNotContainsString(ContainerExcluded::class, $tester->getDisplay());
100+
}
101+
88102
/**
89103
* @dataProvider provideIgnoreBackslashWhenFindingService
90104
*/

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDebug/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ services:
3333
- '%env(REAL)%'
3434
- '%env(int:key:2:json:JSON)%'
3535
- '%env(float:key:2:json:JSON)%'
36+
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\ContainerExcluded:
37+
tags: ['container.excluded']

0 commit comments

Comments
 (0)