Skip to content

Commit 43d9aae

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

22 files changed

+121
-43
lines changed

UPGRADE-3.3.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ FrameworkBundle
236236
class has been deprecated and will be removed in 4.0.
237237
Use the `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` class instead.
238238

239+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass`
240+
class has been deprecated and will be removed in 4.0.
241+
242+
* The `debug.container.dump` parameter has been removed, the debug
243+
container is now dumped from the `debug:container` command itself.
244+
239245
HttpFoundation
240246
--------------
241247

UPGRADE-4.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ FrameworkBundle
326326
removed. Use the `Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass`
327327
class instead.
328328

329+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass`
330+
class has been removed.
331+
329332
HttpFoundation
330333
--------------
331334

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ CHANGELOG
4545
`Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass` instead
4646
* Deprecated `AddConstraintValidatorsPass`, use
4747
`Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` instead
48+
* Deprecated `ContainerBuilderDebugDumpPass`
4849

4950
3.2.0
5051
-----

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
15+
use Symfony\Component\Config\ConfigCache;
16+
use Symfony\Component\Config\Resource\FileResource;
1517
use Symfony\Component\Console\Input\InputArgument;
1618
use Symfony\Component\Console\Input\InputOption;
1719
use Symfony\Component\Console\Input\InputInterface;
1820
use Symfony\Component\Console\Output\OutputInterface;
1921
use Symfony\Component\Console\Style\SymfonyStyle;
22+
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
2023
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2124
use Symfony\Component\DependencyInjection\ContainerBuilder;
2225
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -176,19 +179,21 @@ protected function getContainerBuilder()
176179
return $this->containerBuilder;
177180
}
178181

179-
if (!$this->getApplication()->getKernel()->isDebug()) {
180-
throw new \LogicException('Debug information about the container is only available in debug mode.');
181-
}
182-
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.');
182+
$kernel = $this->getApplication()->getKernel();
183+
$cacheDir= $kernel->getCacheDir();
184+
$containerClass = $kernel->getContainer()->getParameter('kernel.container_class');
185+
$cache = new ConfigCache($cacheDir.'/'.$containerClass.'.xml', true);
186+
187+
if (!$cache->isFresh()) {
188+
$buildContainer = \Closure::bind(function () { return $this->buildContainer(); }, $kernel, get_class($kernel));
189+
$container = $buildContainer();
190+
$container->getCompilerPassConfig()->setRemovingPasses(array());
191+
$container->compile();
192+
$cache->write((new XmlDumper($container))->dump(), array(new FileResource($cacheDir.'/'.$containerClass.'.php')));
193+
} else {
194+
(new XmlFileLoader($container = new ContainerBuilder(), new FileLocator()))->load($cache->getPath());
185195
}
186196

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

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(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0.', ContainerBuilderDebugDumpPass::class), E_USER_DEPRECATED);
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 <ryan@thatsquality.com>
2527
* @author Fabien Potencier <fabien@symfony.com>
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
}

0 commit comments

Comments
 (0)