10000 [DI][FrameworkBundle] Hide service ids that start with a dot · symfony/symfony@c689088 · GitHub
[go: up one dir, main page]

Skip to content

Commit c689088

Browse files
[DI][FrameworkBundle] Hide service ids that start with a dot
1 parent 9a99955 commit c689088

File tree

58 files changed

+262
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+262
-264
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ protected function configure()
4848
$this
4949
->setDefinition(array(
5050
new InputArgument('name', InputArgument::OPTIONAL, 'A service name (foo)'),
51-
new InputOption('show-private', null, InputOption::VALUE_NONE, 'Used to show public *and* private services'),
< E377 /td>
51+
new InputOption('show-private', null, InputOption::VALUE_NONE, 'Used to show public *and* private services (deprecated)'),
5252
new InputOption('show-arguments', null, InputOption::VALUE_NONE, 'Used to show arguments in services'),
53+
new InputOption('show-hidden', null, InputOption::VALUE_NONE, 'Used to show hidden (internal) services'),
5354
new InputOption('tag', null, InputOption::VALUE_REQUIRED, 'Shows all services with a specific tag'),
5455
new InputOption('tags', null, InputOption::VALUE_NONE, 'Displays tagged services for an application'),
5556
new InputOption('parameter', null, InputOption::VALUE_REQUIRED, 'Displays a specific parameter for an application'),
@@ -72,11 +73,6 @@ protected function configure()
7273
7374
<info>php %command.full_name% --types</info>
7475
75-
By default, private services are hidden. You can display all services by
76-
using the <info>--show-private</info> flag:
77-
78-
<info>php %command.full_name% --show-private</info>
79-
8076
Use the --tags option to display tagged <comment>public</comment> services grouped by tag:
8177
8278
<info>php %command.full_name% --tags</info>
@@ -103,14 +99,18 @@ protected function configure()
10399
*/
104100
protected function execute(InputInterface $input, OutputInterface $output)
105101
{
102+
if ($input->getOption('show-private')) {
103+
@trigger_error('The "--show-private" option no longer has any effect and is deprecated since Symfony 4.1.', E_USER_DEPRECATED);
104+
}
105+
106106
$io = new SymfonyStyle($input, $output);
107107
$errorIo = $io->getErrorStyle();
108108

109109
$this->validateInput($input);
110110
$object = $this->getContainerBuilder();
111111

112112
if ($input->getOption('types')) {
113-
$options = array('show_private' => true);
113+
$options = array();
114114
$options['filter'] = array($this, 'filterToServiceTypes');
115115
} elseif ($input->getOption('parameters')) {
116116
$parameters = array();
@@ -122,19 +122,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
122122
} elseif ($parameter = $input->getOption('parameter')) {
123123
$options = array('parameter' => $parameter);
124124
} elseif ($input->getOption('tags')) {
125-
$options = array('group_by' => 'tags', 'show_private' => $input->getOption('show-private'));
125+
$options = array('group_by' => 'tags');
126126
} elseif ($tag = $input->getOption('tag')) {
127-
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
127+
$options = array('tag' => $tag);
128128
} elseif ($name = $input->getArgument('name')) {
129129
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
130130
$options = array('id' => $name);
131131
} else {
132-
$options = array('show_private' => $input->getOption('show-private'));
132+
$options = array();
133133
}
134134

135135
$helper = new DescriptorHelper();
136136
$options['format'] = $input->getOption('format');
137137
$options['show_arguments'] = $input->getOption('show-arguments');
138+
$options['show_hidden'] = $input->getOption('show-hidden');
138139
$options['raw_text'] = $input->getOption('raw');
139140
$options['output'] = $io;
140141
$helper->describe($io, $object, $options);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use Symfony\Component\DependencyInjection\Alias;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\ContainerInterface;
1819
use Symfony\Component\DependencyInjection\Definition;
1920
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2021
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -230,17 +231,21 @@ protected function resolveServiceDefinition(ContainerBuilder $builder, $serviceI
230231
return $builder->getAlias($serviceId);
231232
}
232233

234+
if ('service_container' === $serviceId) {
235+
return (new Definition(ContainerInterface::class))->setPublic(true)->setSynthetic(true);
236+
}
237+
233238
// the service has been injected in some special way, just return the service
234239
return $builder->get($serviceId);
235240
}
236241

237242
/**
238243
* @param ContainerBuilder $builder
239-
* @param bool $showPrivate
244+
* @param bool $showHidden
240245
*
241246
* @return array
242247
*/
243-
protected function findDefinitionsByTag(ContainerBuilder $builder, $showPrivate)
248+
protected function findDefinitionsByTag(ContainerBuilder $builder, $showHidden)
244249
{
245250
$definitions = array();
246251
$tags = $builder->findTags();
@@ -250,7 +255,7 @@ protected function findDefinitionsByTag(ContainerBuilder $builder, $showPrivate)
250255
foreach ($builder->findTaggedServiceIds($tag) as $serviceId => $attributes) {
251256
$definition = $this->resolveServiceDefinition($builder, $serviceId);
252257

253-
if (!$definition instanceof Definition || !$showPrivate && !$definition->isPublic()) {
258+
if ($showHidden xor '.' === $serviceId[0] ?? null) {
254259
continue;
255260
}
256261

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ protected function describeContainerParameters(ParameterBag $parameters, array $
6363
*/
6464
protected function describeContainerTags(ContainerBuilder $builder, array $options = array())
6565
{
66-
$showPrivate = isset($options['show_private']) && $options['show_private'];
66+
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
6767
$data = array();
6868

69-
foreach ($this->findDefinitionsByTag($builder, $showPrivate) as $tag => $definitions) {
69+
foreach ($this->findDefinitionsByTag($builder, $showHidden) as $tag => $definitions) {
7070
$data[$tag] = array();
7171
foreach ($definitions as $definition) {
7272
$data[$tag][] = $this->getContainerDefinitionData($definition, true);
@@ -100,7 +100,7 @@ protected function describeContainerService($service, array $options = array(),
100100
protected function describeContainerServices(ContainerBuilder $builder, array $options = array())
101101
{
102102
$serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds();
103-
$showPrivate = isset($options['show_private']) && $options['show_private'];
103+
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
104104
$omitTags = isset($options['omit_tags']) && $options['omit_tags'];
105105
$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
106106
$data = array('definitions' => array(), 'aliases' => array(), 'services' => array());
@@ -112,14 +112,14 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
112112
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
113113
$service = $this->resolveServiceDefinition($builder, $serviceId);
114114

115+
if ($showHidden xor '.' === $serviceId[0] ?? null) {
116+
continue;
117+
}
118+
115119
if ($service instanceof Alias) {
116-
if ($showPrivate || ($service->isPublic() && !$service->isPrivate())) {
117-
$data['aliases'][$serviceId] = $this->getContainerAliasData($service);
118-
}
120+
$data['aliases'][$serviceId] = $this->getContainerAliasData($service);
119121
} elseif ($service instanceof Definition) {
120-
if (($showPrivate || ($service->isPublic() && !$service->isPrivate()))) {
121-
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments);
122-
}
122+
$data['definitions'][$serviceId] = $this->getContainerDefinitionData($service, $omitTags, $showArguments);
123123
} else {
124124
$data['services'][$serviceId] = get_class($service);
125125
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ protected function describeContainerParameters(ParameterBag $parameters, array $
8282
*/
8383
protected function describeContainerTags(ContainerBuilder $builder, array $options = array())
8484
{
85-
$showPrivate = isset($options['show_private']) && $options['show_private'];
85+
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
8686
$this->write("Container tags\n==============");
8787

88-
foreach ($this->findDefinitionsByTag($builder, $showPrivate) as $tag => $definitions) {
88+
foreach ($this->findDefinitionsByTag($builder, $showHidden) as $tag => $definitions) {
8989
$this->write("\n\n".$tag."\n".str_repeat('-', strlen($tag)));
9090
foreach ($definitions as $serviceId => $definition) {
9191
$this->write("\n\n");
@@ -119,9 +119,9 @@ protected function describeContainerService($service, array $options = array(),
119119
*/
120120
protected function describeContainerServices(ContainerBuilder $builder, array $options = array())
121121
{
122-
$showPrivate = isset($options['show_private']) && $options['show_private'];
122+
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
123123

124-
$title = $showPrivate ? 'Public and private services' : 'Public services';
124+
$title = $showHidden ? 'Hidden services' : 'Services';
125125
if (isset($options['tag'])) {
126126
$title .= ' with tag `'.$options['tag'].'`';
127127
}
@@ -138,14 +138,14 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
138138
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
139139
$service = $this->resolveServiceDefinition($builder, $serviceId);
140140

141+
if ($showHidden xor '.' === $serviceId[0] ?? null) {
142+
continue;
143+
}
144+
141145
if ($service instanceof Alias) {
142-
if ($showPrivate || ($service->isPublic() && !$service->isPrivate())) {
143-
$services['aliases'][$serviceId] = $service;
144-
}
146+
$services['aliases'][$serviceId] = $service;
145147
} elseif ($service instanceof Definition) {
146-
if (($showPrivate || ($service->isPublic() && !$service->isPrivate()))) {
147-
$services['definitions'][$serviceId] = $service;
148-
}
148+
$services['definitions'][$serviceId] = $service;
149149
} else {
150150
$services['services'][$serviceId] = $service;
151151
}

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ protected function describeContainerParameters(Para 341A meterBag $parameters, array $
122122
*/
123123
protected function describeContainerTags(ContainerBuilder $builder, array $options = array())
124124
{
125-
$showPrivate = isset($options['show_private']) && $options['show_private'];
125+
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
126126

127-
if ($showPrivate) {
128-
$options['output']->title('Symfony Container Public and Private Tags');
127+
if ($showHidden) {
128+
$options['output']->title('Symfony Container Hidden Tags');
129129
} else {
130-
$options['output']->title('Symfony Container Public Tags');
130+
$options['output']->title('Symfony Container Tags');
131131
}
132132

133-
foreach ($this->findDefinitionsByTag($builder, $showPrivate) as $tag => $definitions) {
133+
foreach ($this->findDefinitionsByTag($builder, $showHidden) as $tag => $definitions) {
134134
$options['output']->section(sprintf('"%s" tag', $tag));
135135
$options['output']->listing(array_keys($definitions));
136136
}
@@ -165,13 +165,13 @@ protected function describeContainerService($service, array $options = array(),
165165
*/
166166
protected function describeContainerServices(ContainerBuilder $builder, array $options = array())
167167
{
168-
$showPrivate = isset($options['show_private']) && $options['show_private'];
168+
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
169169
$showTag = isset($options['tag']) ? $options['tag'] : null;
170170

171-
if ($showPrivate) {
172-
$title = 'Symfony Container Public and Private Services';
171+
if ($showHidden) {
172+
$title = 'Symfony Container Hidden Services';
173173
} else {
174-
$title = 'Symfony Container Public Services';
174+
$title = 'Symfony Container Services';
175175
}
176176

177177
if ($showTag) {
@@ -189,12 +189,14 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
189189

190190
foreach ($serviceIds as $key => $serviceId) {
191191
$definition = $this->resolveServiceDefinition($builder, $serviceId);
192+
193+
// filter out hidden services unless shown explicitly
194+
if ($showHidden xor '.' === $serviceId[0] ?? null) {
195+
unset($serviceIds[$key]);
196+
continue;
197+
}
198+
192199
if ($definition instanceof Definition) {
193-
// filter out private services unless shown explicitly
194-
if (!$showPrivate && (!$definition->isPublic() || $definition->isPrivate())) {
195-
unset($serviceIds[$key]);
196-
continue;
197-
}
198200
if ($showTag) {
199201
$tags = $definition->getTag($showTag);
200202
foreach ($tags as $tag) {
@@ -208,11 +210,6 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
208210
}
209211
}
210212
}
211-
} elseif ($definition instanceof Alias) {
212-
if (!$showPrivate && (!$definition->isPublic() || $definition->isPrivate())) {
213-
unset($serviceIds[$key]);
214-
continue;
215-
}
216213
}
217214
}
218215

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function describeContainerParameters(ParameterBag $parameters, array $
5858
*/
5959
protected function describeContainerTags(ContainerBuilder $builder, array $options = array())
6060
{
61-
$this->writeDocument($this->getContainerTagsDocument($builder, isset($options['show_private']) && $options['show_private']));
61+
$this->writeDocument($this->getContainerTagsDocument($builder, isset($options['show_hidden']) && $options['show_hidden']));
6262
}
6363

6464
/**
@@ -78,7 +78,7 @@ protected function describeContainerService($service, array $options = array(),
7878
*/
7979
protected function describeContainerServices(ContainerBuilder $builder, array $options = array())
8080
{
81-
$this->writeDocument($this->getContainerServicesDocument($builder, isset($options['tag']) ? $options['tag'] : null, isset($options['show_private']) && $options['show_private'], isset($options['show_arguments']) && $options['show_arguments'], isset($options['filter']) ? $options['filter'] : null));
81+
$this->writeDocument($this->getContainerServicesDocument($builder, isset($options['tag']) ? $options['tag'] : null, isset($options['show_hidden']) && $options['show_hidden'], isset($options['show_arguments']) && $options['show_arguments'], isset($options['filter']) ? $options['filter'] : null));
8282
}
8383

8484
/**
@@ -231,12 +231,12 @@ private function getContainerParametersDocument(ParameterBag $parameters): \DOMD
231231
return $dom;
232232
}
233233

234-
private function getContainerTagsDocument(ContainerBuilder $builder, bool $showPrivate = false): \DOMDocument
234+
private function getContainerTagsDocument(ContainerBuilder $builder, bool $showHidden = false): \DOMDocument
235235
{
236236
$dom = new \DOMDocument('1.0', 'UTF-8');
237237
$dom->appendChild($containerXML = $dom->createElement('container'));
238238

239-
foreach ($this->findDefinitionsByTag($builder, $showPrivate) as $tag => $definitions) {
239+
foreach ($this->findDefinitionsByTag($builder, $showHidden) as $tag => $definitions) {
240240
$containerXML->appendChild($tagXML = $dom->createElement('tag'));
241241
$tagXML->setAttribute('name', $tag);
242242

@@ -269,7 +269,7 @@ private function getContainerServiceDocument($service, string $id, ContainerBuil
269269
return $dom;
270270
}
271271

272-
private function getContainerServicesDocument(ContainerBuilder $builder, string $tag = null, bool $showPrivate = false, bool $showArguments = false, callable $filter = null): \DOMDocument
272+
private function getContainerServicesDocument(ContainerBuilder $builder, string $tag = null, bool $showHidden = false, bool $showArguments = false, callable $filter = null): \DOMDocument
273273
{
274274
$dom = new \DOMDocument('1.0', 'UTF-8');
275275
$dom->appendChild($containerXML = $dom->createElement('container'));
@@ -283,7 +283,7 @@ private function getContainerServicesDocument(ContainerBuilder $builder, string
283283
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
284284
$service = $this->resolveServiceDefinition($builder, $serviceId);
285285

286-
if (($service instanceof Definition || $service instanceof Alias) && !($showPrivate || ($service->isPublic() && !$service->isPrivate()))) {
286+
if ($showHidden xor '.' === $serviceId[0] ?? null) {
287287
continue;
288288
}
289289

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function getServiceProvider(ContainerBuilder $container, $name)
134134
if ($usedEnvs || preg_match('#^[a-z]++://#', $name)) {
135135
$dsn = $name;
136136

137-
if (!$container->hasDefinition($name = 'cache_connection.'.ContainerBuilder::hash($dsn))) {
137+
if (!$container->hasDefinition($name = '.cache_connection.'.ContainerBuilder::hash($dsn))) {
138138
$definition = new Definition(AbstractAdapter::class);
139139
$definition->setPublic(false);
140140
$definition->setFactory(array(AbstractAdapter::class, 'createConnection'));

0 commit comments

Comments
 (0)
0