Skip to content

Commit d18ba64

Browse files
committed
Show private aliases in debug:container
1 parent 9950b90 commit d18ba64

15 files changed

+39
-36
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Style\SymfonyStyle;
20+
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
2021
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2122
use Symfony\Component\DependencyInjection\ContainerBuilder;
2223
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2324
use Symfony\Component\Config\FileLocator;
25+
use Symfony\Component\Filesystem\Exception\IOException;
26+
use Symfony\Component\Filesystem\Filesystem;
27+
use Symfony\Component\HttpKernel\Kernel;
2428

2529
/**
2630
* A console command for retrieving information about services.
@@ -176,19 +180,30 @@ protected function getContainerBuilder()
176180
return $this->containerBuilder;
177181
}
178182

179-
if (!$this->getApplication()->getKernel()->isDebug()) {
183+
$kernel = $this->getApplication()->getKernel();
184+
185+
if (!$kernel->isDebug()) {
180186
throw new \LogicException('Debug information about the container is only available in debug mode.');
181187
}
182188

183-
if (!is_file($cachedFile = $this->getContainer()->getParameter('debug.container.dump'))) {
184-
throw new \LogicException('Debug information about the container could not be found. Please clear the cache and try again.');
189+
if (is_file($cachedFile = $this->getContainer()->getParameter('debug.container.dump'))) {
190+
$container = new ContainerBuilder();
191+
$loader = new XmlFileLoader($container, new FileLocator());
192+
$loader->load($cachedFile);
193+
} else {
194+
$buildContainer = \Closure::bind(function () { return $this->buildContainer(); }, $kernel, Kernel::class);
195+
$container = $buildContainer();
196+
$container->getCompilerPassConfig()->setRemovingPasses(array());
197+
$container->compile();
198+
$filesystem = new Filesystem();
199+
try {
200+
$filesystem->dumpFile($cachedFile, (new XmlDumper($container))->dump());
201+
$filesystem->chmod($cachedFile, 0666, umask());
202+
} catch (IOException $e) {
203+
// discard filesystem failures
204+
}
185205
}
186206

187-
$container = new ContainerBuilder();
188-
189-
$loader = new XmlFileLoader($container, new FileLocator());
190-
$loader->load($cachedFile);
191-
192207
return $this->containerBuilder = $container;
193208
}
194209

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
109109
$service = $this->resolveServiceDefinition($builder, $serviceId);
110110

111111
if ($service instanceof Alias) {
112-
$data['aliases'][$serviceId] = $this->getContainerAliasData($service);
112+
if ($showPrivate || $service->isPublic()) {
113+
$data['aliases'][$serviceId] = $this->getContainerAliasData($service);
114+
}
113115
} elseif ($service instanceof Definition) {
114116
if (($showPrivate || $service->isPublic())) {
115117
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,16 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
128128
$this->write($title."\n".str_repeat('=', strlen($title)));
129129

130130
$serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds();
131-
$showPrivate = isset($options['show_private']) && $options['show_private'];
132131
$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
133132
$services = array('definitions' => array(), 'aliases' => array(), 'services' => array());
134133

135134
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
136135
$service = $this->resolveServiceDefinition($builder, $serviceId);
137136

138137
if ($service instanceof Alias) {
139-
$services['aliases'][$serviceId] = $service;
138+
if ($showPrivate || $service->isPublic()) {
139+
$services['aliases'][$serviceId] = $service;
140+
}
140141
} elseif ($service instanceof Definition) {
141142
if (($showPrivate || $service->isPublic())) {
142143
$services['definitions'][$serviceId] = $service;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
207207
}
208208
}
209209
}
210+
} elseif ($definition instanceof Alias) {
211+
if (!$showPrivate && !$definition->isPublic()) {
212+
unset($serviceIds[$key]);
213+
continue;
214+
}
210215
}
211216
}
212217

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ private function getContainerServicesDocument(ContainerBuilder $builder, $tag =
320320
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
321321
$service = $this->resolveServiceDefinition($builder, $serviceId);
322322

323-
if ($service instanceof Definition && !($showPrivate || $service->isPublic())) {
323+
if (($service instanceof Definition || $service instanceof Alias) && !($showPrivate || $service->isPublic())) {
324324
continue;
325325
}
326326

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ContainerBuilderDebugDumpPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
@trigger_error('The %s class is deprecated since version 3.3 and will be removed in 4.0.', ContainerBuilderDebugDumpPass::class);
15+
1416
use Symfony\Component\DependencyInjection\ContainerBuilder;
1517
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
1618
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -23,6 +25,8 @@
2325
*
2426
* @author Ryan Weaver <[email protected]>
2527
* @author Fabien Potencier <[email protected]>
28+
*
29+
* @deprecated since version 3.3, to be removed in 4.0
2630
*/
2731
class ContainerBuilderDebugDumpPass implements CompilerPassInterface
2832
{

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
2525
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass;
2626
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
27-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
2827
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
2928
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
3029
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
@@ -113,7 +112,6 @@ public function build(ContainerBuilder $container)
113112
if ($container->getParameter('kernel.debug')) {
114113
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
115114
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
116-
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
117115
$this->addCompilerPassIfExists($container, ConfigCachePass::class);
118116
$container->addCompilerPass(new CacheCollectorPass());
119117
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@
7676
"alias_1": {
7777
"service": "service_1",
7878
"public": true
79-
},
80-
"alias_2": {
81-
"service": "service_2",
82-
"public": false
8379
}
8480
},
8581
"services": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ Aliases
2626
- Service: `service_1`
2727
- Public: yes
2828

29-
### alias_2
30-
31-
- Service: `service_2`
32-
- Public: no
33-
3429

3530
Services
3631
--------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
 Service ID   Class name 
77
------------------- --------------------------------------------------------
88
alias_1 alias for "service_1"
9-
alias_2 alias for "service_2"
109
definition_1 Full\Qualified\Class1
1110
service_container Symfony\Component\DependencyInjection\ContainerBuilder
1211
------------------- --------------------------------------------------------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<container>
33
<alias id="alias_1" service="service_1" public="true"/>
4-
<alias id="alias_2" service="service_2" public="false"/>
54
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" file="">
65
<factory class="Full\Qualified\FactoryClass" method="get"/>
76
<argument type="service" id="definition2"/>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
"alias_1": {
1919
"service": "service_1",
2020
"public": true
21-
},
22-
"alias_2": {
23-
"service": "service_2",
24-
"public": false
2521
}
2622
},
2723
"services": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ Aliases
2525
- Service: `service_1`
2626
- Public: yes
2727

28-
### alias_2
29-
30-
- Service: `service_2`
31-
- Public: no
32-
3328

3429
Services
3530
--------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
 Service ID   Class name 
77
------------------- --------------------------------------------------------
88
alias_1 alias for "service_1"
9-
alias_2 alias for "service_2"
109
definition_1 Full\Qualified\Class1
1110
service_container Symfony\Component\DependencyInjection\ContainerBuilder
1211
------------------- --------------------------------------------------------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<container>
33
<alias id="alias_1" service="service_1" public="true"/>
4-
<alias id="alias_2" service="service_2" public="false"/>
54
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" autowired="false" file="">
65
<factory class="Full\Qualified\FactoryClass" method="get"/>
76
</definition>

0 commit comments

Comments
 (0)