Skip to content

Commit 24a5f20

Browse files
minor #49472 [DependencyInjection] Only dump array keys when value is not a list (ruudk)
This PR was merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Only dump array keys when value is not a list | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? |no | Deprecations? | no | Tickets | | License | MIT | Doc PR | When the value is a list, there is no point in dumping the keys. Commits ------- a46e46f Only dump array keys when value is not a list
2 parents 6d29f32 + a46e46f commit 24a5f20

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,9 +1796,10 @@ private function dumpValue(mixed $value, bool $interpolate = true): string
17961796
if ($value && $interpolate && false !== $param = array_search($value, $this->container->getParameterBag()->all(), true)) {
17971797
return $this->dumpValue("%$param%");
17981798
}
1799+
$isList = array_is_list($value);
17991800
$code = [];
18001801
foreach ($value as $k => $v) {
1801-
$code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));
1802+
$code[] = $isList ? $this->dumpValue($v, $interpolate) : sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));
18021803
}
18031804

18041805
return sprintf('[%s]', implode(', ', $code));

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10_as_files.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class getClosureService extends ProjectServiceContainer
3131

3232
$container->services['closure'] = $instance = new \stdClass();
3333

34-
$instance->closures = [0 => #[\Closure(name: 'foo', class: 'FooClass')] static function () use ($containerRef): ?\stdClass {
34+
$instance->closures = [#[\Closure(name: 'foo', class: 'FooClass')] static function () use ($containerRef): ?\stdClass {
3535
$container = $containerRef->get();
3636

3737
return ($container->services['foo'] ?? null);

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_adawson.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected static function getBusService($container)
6363

6464
$b = ($container->privates['App\\Schema'] ?? self::getSchemaService($container));
6565
$c = new \App\Registry();
66-
$c->processor = [0 => $a, 1 => $instance];
66+
$c->processor = [$a, $instance];
6767

6868
$d = new \App\Processor($c, $a);
6969

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_private.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected static function getManager3Service($container, $lazyLoad = true)
385385
return $container->services['manager3'];
386386
}
387387
$b = new \stdClass();
388-
$b->listener = [0 => $a];
388+
$b->listener = [$a];
389389

390390
return $container->services['manager3'] = new \stdClass($b);
391391
}
@@ -588,7 +588,7 @@ protected static function getManager4Service($container, $lazyLoad = true)
588588

589589
$container->privates['manager4'] = $instance = new \stdClass($a);
590590

591-
$a->listener = [0 => ($container->services['listener4'] ?? self::getListener4Service($container))];
591+
$a->listener = [($container->services['listener4'] ?? self::getListener4Service($container))];
592592

593593
return $instance;
594594
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_public.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ protected static function getConnection3Service($container)
219219
{
220220
$container->services['connection3'] = $instance = new \stdClass();
221221

222-
$instance->listener = [0 => ($container->services['listener3'] ?? self::getListener3Service($container))];
222+
$instance->listener = [($container->services['listener3'] ?? self::getListener3Service($container))];
223223

224224
return $instance;
225225
}
@@ -233,7 +233,7 @@ protected static function getConnection4Service($container)
233233
{
234234
$container->services['connection4'] = $instance = new \stdClass();
235235

236-
$instance->listener = [0 => ($container->services['listener4'] ?? self::getListener4Service($container))];
236+
$instance->listener = [($container->services['listener4'] ?? self::getListener4Service($container))];
237237

238238
return $instance;
239239
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_uninitialized_ref.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ protected static function getBarService($container)
6262
$instance->foo1 = ($container->services['foo1'] ?? null);
6363
$instance->foo2 = null;
6464
$instance->foo3 = ($container->privates['foo3'] ?? null);
65-
$instance->closures = [0 => #[\Closure(name: 'foo1', class: 'stdClass')] static function () use ($containerRef) {
65+
$instance->closures = [#[\Closure(name: 'foo1', class: 'stdClass')] static function () use ($containerRef) {
6666
$container = $containerRef->get();
6767

6868
return ($container->services['foo1'] ?? null);
69-
}, 1 => #[\Closure(name: 'foo2')] static function () use ($containerRef) {
69+
}, #[\Closure(name: 'foo2')] static function () use ($containerRef) {
7070
$container = $containerRef->get();
7171

7272
return null;
73-
}, 2 => #[\Closure(name: 'foo3', class: 'stdClass')] static function () use ($containerRef) {
73+
}, #[\Closure(name: 'foo3', class: 'stdClass')] static function () use ($containerRef) {
7474
$container = $containerRef->get();
7575

7676
return ($container->privates['foo3'] ?? null);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy