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

Appearance settings

Commit c0d418d

Browse filesBrowse files
committed
Show private aliases in debug:container
1 parent 9950b90 commit c0d418d
Copy full SHA for c0d418d

18 files changed

+133
-47
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
15+
use Symfony\Component\Config\ConfigCache;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Symfony\Component\Console\Style\SymfonyStyle;
21+
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
2022
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2123
use Symfony\Component\DependencyInjection\ContainerBuilder;
2224
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -176,19 +178,17 @@ protected function getContainerBuilder()
176178
return $this->containerBuilder;
177179
}
178180

179-
if (!$this->getApplication()->getKernel()->isDebug()) {
180-
throw new \LogicException('Debug information about the container is only available in debug mode.');
181-
}
181+
$kernel = $this->getApplication()->getKernel();
182182

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.');
183+
if (!$kernel->isDebug() || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
184+
$buildContainer = \Closure::bind(function () { return $this->buildContainer(); }, $kernel, get_class($kernel));
185+
$container = $buildContainer();
186+
$container->getCompilerPassConfig()->setRemovingPasses(array());
187+
$container->compile();
188+
} else {
189+
(new XmlFileLoader($container = new ContainerBuilder(), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
185190
}
186191

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
+3-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
+3-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
+5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ContainerBuilderDebugDumpPass.php
+17-10Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

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

14+
use Symfony\Component\Config\ConfigCache;
15+
use Symfony\Component\DependencyInjection\Compiler\Compiler;
1416
use Symfony\Component\DependencyInjection\ContainerBuilder;
1517
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
1618
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17-
use Symfony\Component\Filesystem\Exception\IOException;
18-
use Symfony\Component\Filesystem\Filesystem;
1919

2020
/**
2121
* Dumps the ContainerBuilder to a cache file so that it can be used by
@@ -28,14 +28,21 @@ class ContainerBuilderDebugDumpPass implements CompilerPassInterface
2828
{
2929
public function process(ContainerBuilder $container)
3030
{
31-
$dumper = new XmlDumper($container);
32-
$filename = $container->getParameter('debug.container.dump');
33-
$filesystem = new Filesystem();
34-
$filesystem->dumpFile($filename, $dumper->dump(), null);
35-
try {
36-
$filesystem->chmod($filename, 0666, umask());
37-
} catch (IOException $e) {
38-
// discard chmod failure (some filesystem may not support it)
31+
$debugContainer = new ContainerBuilder();
32+
$debugContainer->merge($container);
33+
34+
// unset removing passes so that private/unused defintions/aliases are dumped
35+
$passConfig = $debugContainer->getCompilerPassConfig();
36+
$passConfig->setRemovingPasses(array());
37+
$passConfig->setBeforeRemovingPasses(array_map(function (CompilerPassInterface $pass) {
38+
return !$pass instanceof self;
39+
}, $passConfig->getBeforeRemovingPasses()));
40+
41+
$debugContainer->compile();
42+
43+
$cache = new ConfigCache($container->getParameter('debug.container.dump'), true);
44+
if (!$cache->isFresh()) {
45+
$cache->write((new XmlDumper($debugContainer))->dump(), $debugContainer->getResources());
3946
}
4047
}
4148
}

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function build(ContainerBuilder $container)
113113
if ($container->getParameter('kernel.debug')) {
114114
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
115115
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
116-
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
116+
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
117117
$this->addCompilerPassIfExists($container, ConfigCachePass::class);
118118
$container->addCompilerPass(new CacheCollectorPass());
119119
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json
-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.md
-5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.txt
-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml
-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json
-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md
-5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.txt
-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml
-1Lines 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>
+66Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Console\Application;
15+
use Symfony\Component\Console\Tester\ApplicationTester;
16+
17+
/**
18+
* @group functional
19+
*/
20+
class ContainerDebugCommandTest extends WebTestCase
21+
{
22+
public function testDumpContainerIfNotExists()
23+
{
24+
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml'));
25+
26+
$application = new Application(static::$kernel);
27+
$application->setAutoExit(false);
28+
29+
@unlink(static::$kernel->getContainer()->getParameter('debug.container.dump'));
30+
31+
$tester = new ApplicationTester($application);
32+
$tester->run(array('command' => 'debug:container'));
33+
34+
$this->assertFileExists(static::$kernel->getContainer()->getParameter('debug.container.dump'));
35+
}
36+
37+
public function testNoDebug()
38+
{
39+
static::bootKernel(array('test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => false));
40+
41+
$application = new Application(static::$kernel);
42+
$application->setAutoExit(false);
43+
44+
$tester = new ApplicationTester($application);
45+
$tester->run(array('command' => 'debug:container'));
46+
47+
$this->assertContains('public', $tester->getDisplay());
48+
}
49+
50+
public function testPrivateAlias()
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:container', '--show-private' => true));
59+
$this->assertContains('public', $tester->getDisplay());
60+
$this->assertContains('private_alias', $tester->getDisplay());
61+
62+
$tester->run(array('command' => 'debug:container'));
63+
$this->assertContains('public', $tester->getDisplay());
64+
$this->assertNotContains('private_alias', $tester->getDisplay());
65+
}
66+
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
13+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
14+
15+
return array(
16+
new FrameworkBundle(),
17+
new TestBundle(),
18+
);
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
services:
5+
public:
6+
class: Symfony\Bundle\FrameworkBundle\Tests\Fixtures\DeclaredClass
7+
private_alias:
8+
alias: public
9+
public: false

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.