Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit09f22f4

Browse files
committed
feature#22385 [DX][FrameworkBundle] Show private aliases in debug:container (chalasr)
This PR was merged into the 3.3-dev branch.Discussion----------[DX][FrameworkBundle] Show private aliases in debug:container| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#16388Haehnchen/idea-php-symfony2-plugin#618| License | MIT| Doc PR | n/aBy building and compiling the container without `TYPE_REMOVING` passes, private aliases are available (shown when `--show-private` is passed). The ContainerBuilderDebugDumpPass now makes use of the ConfigCache component, removing the need for clearing the cache to get the debug:container output up to date (in sync with latest config).Config-------```yamlservices: AppBundle\Foo: public: false foo_consumer1: class: AppBundle\Foo arguments: [ '@appbundle\Foo' ] foo_consumer2: class: AppBundle\Foo arguments: [ '@appbundle\Foo' ] foo_alias: alias: AppBundle\Foo foo_private_alias: public: false alias: AppBundle\Foo```Before-------![before](http://image.prntscr.com/image/2a69485a4a764316a90260b4e3dfc2a2.png)After------![after](http://image.prntscr.com/image/ea42daa0e5c94841a28dd256450dc8ef.png)Commits-------883723e Show private aliases in debug:container
2 parentsc89d2f9 +883723e commit09f22f4

File tree

18 files changed

+119
-47
lines changed

18 files changed

+119
-47
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Bundle\FrameworkBundle\Command;
1313

1414
useSymfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
15+
useSymfony\Component\Config\ConfigCache;
1516
useSymfony\Component\Console\Input\InputArgument;
1617
useSymfony\Component\Console\Input\InputOption;
1718
useSymfony\Component\Console\Input\InputInterface;
@@ -176,19 +177,17 @@ protected function getContainerBuilder()
176177
return$this->containerBuilder;
177178
}
178179

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

183-
if (!is_file($cachedFile =$this->getContainer()->getParameter('debug.container.dump'))) {
184-
thrownew \LogicException('Debug information about the container could not be found. Please clear the cache and try again.');
182+
if (!$kernel->isDebug() || !(newConfigCache($kernel->getContainer()->getParameter('debug.container.dump'),true))->isFresh()) {
183+
$buildContainer = \Closure::bind(function () {return$this->buildContainer(); },$kernel,get_class($kernel));
184+
$container =$buildContainer();
185+
$container->getCompilerPassConfig()->setRemovingPasses(array());
186+
$container->compile();
187+
}else {
188+
(newXmlFileLoader($container =newContainerBuilder(),newFileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
185189
}
186190

187-
$container =newContainerBuilder();
188-
189-
$loader =newXmlFileLoader($container,newFileLocator());
190-
$loader->load($cachedFile);
191-
192191
return$this->containerBuilder =$container;
193192
}
194193

‎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 ($serviceinstanceof Alias) {
112-
$data['aliases'][$serviceId] =$this->getContainerAliasData($service);
112+
if ($showPrivate ||$service->isPublic()) {
113+
$data['aliases'][$serviceId] =$this->getContainerAliasData($service);
114+
}
113115
}elseif ($serviceinstanceof 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 ($serviceinstanceof Alias) {
139-
$services['aliases'][$serviceId] =$service;
138+
if ($showPrivate ||$service->isPublic()) {
139+
$services['aliases'][$serviceId] =$service;
140+
}
140141
}elseif ($serviceinstanceof 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 ($definitioninstanceof 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 ($serviceinstanceof Definition && !($showPrivate ||$service->isPublic())) {
323+
if (($serviceinstanceof Definition ||$serviceinstanceof Alias) && !($showPrivate ||$service->isPublic())) {
324324
continue;
325325
}
326326

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

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

1212
namespaceSymfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
useSymfony\Component\Config\ConfigCache;
1415
useSymfony\Component\DependencyInjection\ContainerBuilder;
1516
useSymfony\Component\DependencyInjection\Dumper\XmlDumper;
1617
useSymfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17-
useSymfony\Component\Filesystem\Exception\IOException;
18-
useSymfony\Component\Filesystem\Filesystem;
1918

2019
/**
2120
* Dumps the ContainerBuilder to a cache file so that it can be used by
@@ -28,14 +27,9 @@ class ContainerBuilderDebugDumpPass implements CompilerPassInterface
2827
{
2928
publicfunctionprocess(ContainerBuilder$container)
3029
{
31-
$dumper =newXmlDumper($container);
32-
$filename =$container->getParameter('debug.container.dump');
33-
$filesystem =newFilesystem();
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)
30+
$cache =newConfigCache($container->getParameter('debug.container.dump'),true);
31+
if (!$cache->isFresh()) {
32+
$cache->write((newXmlDumper($container))->dump(),$container->getResources());
3933
}
4034
}
4135
}

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

Lines 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(newAddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
115115
$container->addCompilerPass(newUnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
116-
$container->addCompilerPass(newContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
116+
$container->addCompilerPass(newContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
117117
$this->addCompilerPassIfExists($container, ConfigCachePass::class);
118118
$container->addCompilerPass(newCacheCollectorPass());
119119
}

‎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
@@ -79,10 +79,6 @@
7979
"alias_1": {
8080
"service":"service_1",
8181
"public":true
82-
},
83-
"alias_2": {
84-
"service":"service_2",
85-
"public":false
8682
}
8783
},
8884
"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
@@ -27,11 +27,6 @@ Aliases
2727
- Service:`service_1`
2828
- Public: yes
2929

30-
###alias_2
31-
32-
- Service:`service_2`
33-
- Public: no
34-
3530

3631
Services
3732
--------

‎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
------------------- --------------------------------------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp