8000 minor #50282 Consistently use var $container to reference the contain… · symfony/symfony@51889c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51889c0

Browse files
minor #50282 Consistently use var $container to reference the container builder+configurator (nicolas-grekas)
This PR was merged into the 6.3 branch. Discussion ---------- Consistently use var $container to reference the container builder+configurator | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Related to symfony/symfony-docs#18299 The vast majority of the code base uses `$container` to reference either the `ContainerBuilder` or the `ContainerConfigurator`, depending on the context. There are just a few inconsistencies, fixed in this PR. Commits ------- 3f2c196 Consistently use var $container to reference the container builder+configurator
2 parents 41e567f + 3f2c196 commit 51889c0

File tree

13 files changed

+172
-172
lines changed

13 files changed

+172
-172
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
trait BuildDebugContainerTrait
2828
{
29-
protected $containerBuilder;
29+
protected ContainerBuilder $container;
3030

3131
/**
3232
* Loads the ContainerBuilder from the cache.
@@ -35,8 +35,8 @@ trait BuildDebugContainerTrait
3535
*/
3636
protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilder
3737
{
38-
if ($this->containerBuilder) {
39-
return $this->containerBuilder;
38+
if (isset($this->container)) {
39+
return $this->container;
4040
}
4141

4242
if (!$kernel->isDebug() || !$kernel->getContainer()->getParameter('debug.container.dump') || !(new ConfigCache($kernel->getContainer()->getParameter('debug.container.dump'), true))->isFresh()) {
@@ -59,6 +59,6 @@ protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilde
5959
$container->getCompilerPassConfig()->setBeforeRemovingPasses([]);
6060
}
6161

62-
return $this->containerBuilder = $container;
62+
return $this->container = $container;
6363
}
6464
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,15 @@ protected function validateInput(InputInterface $input): void
261261
}
262262
}
263263

264-
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, string $name, bool $showHidden): string
264+
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $container, string $name, bool $showHidden): string
265265
{
266266
$name = ltrim($name, '\\');
267267

268-
if ($builder->has($name) || !$input->isInteractive()) {
268+
if ($container->has($name) || !$input->isInteractive()) {
269269
return $name;
270270
}
271271

272-
$matchingServices = $this->findServiceIdsContaining($builder, $name, $showHidden);
272+
$matchingServices = $this->findServiceIdsContaining($container, $name, $showHidden);
273273
if (!$matchingServices) {
274274
throw new InvalidArgumentException(sprintf('No services found that match "%s".', $name));
275275
}
@@ -281,13 +281,13 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
281281
return $io->choice('Select one of the following services to display its information', $matchingServices);
282282
}
283283

284-
private function findProperTagName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, string $tagName): string
284+
private function findProperTagName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $container, string $tagName): string
285285
{
286-
if (\in_array($tagName, $builder->findTags(), true) || !$input->isInteractive()) {
286+
if (\in_array($tagName, $container->findTags(), true) || !$input->isInteractive()) {
287287
return $tagName;
288288
}
289289

290-
$matchingTags = $this->findTagsContaining($builder, $tagName);
290+
$matchingTags = $this->findTagsContaining($container, $tagName);
291291
if (!$matchingTags) {
292292
throw new InvalidArgumentException(sprintf('No tags found that match "%s".', $tagName));
293293
}
@@ -299,15 +299,15 @@ private function findProperTagName(InputInterface $input, SymfonyStyle $io, Cont
299299
return $io->choice('Select one of the following tags to display its information', $matchingTags);
300300
}
301301

302-
private function findServiceIdsContaining(ContainerBuilder $builder, string $name, bool $showHidden): array
302+
private function findServiceIdsContaining(ContainerBuilder $container, string $name, bool $showHidden): array
303303
{
304-
$serviceIds = $builder->getServiceIds();
304+
$serviceIds = $container->getServiceIds();
305305
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = [];
306306
foreach ($serviceIds as $serviceId) {
307307
if (!$showHidden && str_starts_with($serviceId, '.')) {
308308
continue;
309309
}
310-
if (!$showHidden && $builder->hasDefinition($serviceId) && $builder->getDefinition($serviceId)->hasTag('container.excluded')) {
310+
if (!$showHidden && $container->hasDefinition($serviceId) && $container->getDefinition($serviceId)->hasTag('container.excluded')) {
311311
continue;
312312
}
313313
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
@@ -321,9 +321,9 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
321321
return $foundServiceIds ?: $foundServiceIdsIgnoringBackslashes;
322322
}
323323

324-
private function findTagsContaining(ContainerBuilder $builder, string $tagName): array
324+
private function findTagsContaining(ContainerBuilder $container, string $tagName): array
325325
{
326-
$tags = $builder->findTags();
326+
$tags = $container->findTags();
327327
$foundTags = [];
328328
foreach ($tags as $tag) {
329329
if (str_contains($tag, $tagName)) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#[AsCommand(name: 'lint:container', description: 'Ensure that arguments injected into services match type declarations')]
3232
final class ContainerLintCommand extends Command
3333
{
34-
private ContainerBuilder $containerBuilder;
34+
private ContainerBuilder $container;
3535

3636
protected function configure(): void
3737
{
@@ -70,8 +70,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7070

7171
private function getContainerBuilder(): ContainerBuilder
7272
{
73-
if (isset($this->containerBuilder)) {
74-
return $this->containerBuilder;
73+
if (isset($this->container)) {
74+
return $this->container;
7575
}
7676

7777
$kernel = $this->getApplication()->getKernel();
@@ -108,6 +108,6 @@ private function getContainerBuilder(): ContainerBuilder
108108

109109
$container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100);
110110

111-
return $this->containerBuilder = $container;
111+
return $this->container = $container;
112112
}
113113
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7070
$io = new SymfonyStyle($input, $output);
7171
$errorIo = $io->getErrorStyle();
7272

73-
$builder = $this->getContainerBuilder($this->getApplication()->getKernel());
74-
$serviceIds = $builder->getServiceIds();
73+
$container = $this->getContainerBuilder($this->getApplication()->getKernel());
74+
$serviceIds = $container->getServiceIds();
7575
$serviceIds = array_filter($serviceIds, $this->filterToServiceTypes(...));
7676

7777
if ($search = $input->getArgument('search')) {
@@ -98,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9898
$previousId = '-';
9999
$serviceIdsNb = 0;
100100
foreach ($serviceIds as $serviceId) {
101-
if ($builder->hasDefinition($serviceId) && $builder->getDefinition($serviceId)->hasTag('container.excluded')) {
101+
if ($container->hasDefinition($serviceId) && $container->getDefinition($serviceId)->hasTag('container.excluded')) {
102102
continue;
103103
}
104104
$text = [];
@@ -119,11 +119,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
119119
$serviceLine = sprintf('<fg=yellow;href=%s>%s</>', $fileLink, $serviceId);
120120
}
121121

122-
if ($builder->hasAlias($serviceId)) {
122+
if ($container->hasAlias($serviceId)) {
123123
$hasAlias[$serviceId] = true;
124-
$serviceAlias = $builder->getAlias($serviceId);
124+
$serviceAlias = $container->getAlias($serviceId);
125125

126-
if ($builder->hasDefinition($serviceAlias) && $decorated = $builder->getDefinition($serviceAlias)->getTag('container.decorator')) {
126+
if ($container->hasDefinition($serviceAlias) && $decorated = $container->getDefinition($serviceAlias)->getTag('container.decorator')) {
127127
$serviceLine .= ' <fg=cyan>('.$decorated[0]['id'].')</>';
128128
} else {
129129
$serviceLine .= ' <fg=cyan>('.$serviceAlias.')</>';
@@ -135,7 +135,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
135135
} elseif (!$all) {
136136
++$serviceIdsNb;
137137
continue;
138-
} elseif ($builder->getDefinition($serviceId)->isDeprecated()) {
138+
} elseif ($container->getDefinition($serviceId)->isDeprecated()) {
139139
$serviceLine .= ' - <fg=magenta>deprecated</>';
140140
}
141141
$text[] = $serviceLine;
@@ -169,9 +169,9 @@ private function getFileLink(string $class): string
169169
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
170170
{
171171
if ($input->mustSuggestArgumentValuesFor('search')) {
172-
$builder = $this->getContainerBuilder($this->getApplication()->getKernel());
172+
$container = $this->getContainerBuilder($this->getApplication()->getKernel());
173173

174-
$suggestions->suggestValues(array_filter($builder->getServiceIds(), $this->filterToServiceTypes(...)));
174+
$suggestions->suggestValues(array_filter($container->getServiceIds(), $this->filterToServiceTypes(...)));
175175
}
176176
}
177177
}

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ abstract protected function describeRoute(Route $route, array $options = []): vo
8484

8585
abstract protected function describeContainerParameters(ParameterBag $parameters, array $options = []): void;
8686 F438

87-
abstract protected function describeContainerTags(ContainerBuilder $builder, array $options = []): void;
87+
abstract protected function describeContainerTags(ContainerBuilder $container, array $options = []): void;
8888

8989
/**
9090
* Describes a container service by its name.
@@ -94,21 +94,21 @@ abstract protected function describeContainerTags(ContainerBuilder $builder, arr
9494
*
9595
* @param Definition|Alias|object $service
9696
*/
97-
abstract protected function describeContainerService(object $service, array $options = [], ContainerBuilder $builder = null): void;
97+
abstract protected function describeContainerService(object $service, array $options = [], ContainerBuilder $container = null): void;
9898

9999
/**
100100
* Describes container services.
101101
*
102102
* Common options are:
103103
* * tag: filters described services by given tag
104104
*/
105-
abstract protected function describeContainerServices(ContainerBuilder $builder, array $options = []): void;
105+
abstract protected function describeContainerServices(ContainerBuilder $container, array $options = []): void;
106106

107-
abstract protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void;
107+
abstract protected function describeContainerDeprecations(ContainerBuilder $container, array $options = []): void;
108108

109-
abstract protected function describeContainerDefinition(Definition $definition, array $options = [], ContainerBuilder $builder = null): void;
109+
abstract protected function describeContainerDefinition(Definition $definition, array $options = [], ContainerBuilder $container = null): void;
110110

111-
abstract protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null): void;
111+
abstract protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $container = null): void;
112112

113113
abstract protected function describeContainerParameter(mixed $parameter, array $options = []): void;
114114

@@ -170,34 +170,34 @@ protected function formatParameter(mixed $value): string
170170
return (string) $value;
171171
}
172172

173-
protected function resolveServiceDefinition(ContainerBuilder $builder, string $serviceId): mixed
173+
protected function resolveServiceDefinition(ContainerBuilder $container, string $serviceId): mixed
174174
{
175-
if ($builder->hasDefinition($serviceId)) {
176-
return $builder->getDefinition($serviceId);
175+
if ($container->hasDefinition($serviceId)) {
176+
return $container->getDefinition($serviceId);
177177
}
178178

179179
// Some service IDs don't have a Definition, they're aliases
180-
if ($builder->hasAlias($serviceId)) {
181-
return $builder->getAlias($serviceId);
180+
if ($container->hasAlias($serviceId)) {
181+
return $container->getAlias($serviceId);
182182
}
183183

184184
if ('service_container' === $serviceId) {
185185
return (new Definition(ContainerInterface::class))->setPublic(true)->setSynthetic(true);
186186
}
187187

188188
// the service has been injected in some special way, just return the service
189-
return $builder->get($serviceId);
189+
return $container->get($serviceId);
190190
}
191191

192-
protected function findDefinitionsByTag(ContainerBuilder $builder, bool $showHidden): array
192+
protected function findDefinitionsByTag(ContainerBuilder $container, bool $showHidden): array
193193
{
194194
$definitions = [];
195-
$tags = $builder->findTags();
195+
$tags = $container->findTags();
196196
asort($tags);
197197

198198
foreach ($tags as $tag) {
199-
foreach ($builder->findTaggedServiceIds($tag) as $serviceId => $attributes) {
200-
$definition = $this->resolveServiceDefinition($builder, $serviceId);
199+
foreach ($container->findTaggedServiceIds($tag) as $serviceId => $attributes) {
200+
$definition = $this->resolveServiceDefinition($container, $serviceId);
201201

202202
if ($showHidden xor '.' === ($serviceId[0] ?? null)) {
203203
continue;
@@ -334,12 +334,12 @@ private function getContainerEnvVars(ContainerBuilder $container): array
334334
return array_values($envs);
335335
}
336336

337-
protected function getServiceEdges(ContainerBuilder $builder, string $serviceId): array
337+
protected function getServiceEdges(ContainerBuilder $container, string $serviceId): array
338338
{
339339
try {
340340
return array_values(array_unique(array_map(
341341
fn (ServiceReferenceGraphEdge $edge) => $edge->getSourceNode()->getId(),
342-
$builder->getCompiler()->getServiceReferenceGraph()->getNode($serviceId)->getInEdges()
342+
$container->getCompiler()->getServiceReferenceGraph()->getNode($serviceId)->getInEdges()
343343
)));
344344
} catch (InvalidArgumentException $exception) {
345345
return [];

0 commit comments

Comments
 (0)
0