Skip to content

Commit c9c8239

Browse files
bug #57345 [DependencyInjection] Fix regression in ordering service locators by priority (longwave)
This PR was submitted for the 7.1 branch but it was merged into the 7.0 branch instead. Discussion ---------- [DependencyInjection] Fix regression in ordering service locators by priority | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57344 | License | MIT Fixes a regression in Symfony 7.0 where service locators are no longer ordered by priority. Commits ------- d4b812c Allow service locators to be ordered by priority.
2 parents b6ec960 + d4b812c commit c9c8239

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public static function map(array $services): array
131131

132132
$services[$k] = new ServiceClosureArgument($v);
133133
}
134-
ksort($services);
135134

136135
return $services;
137136
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ public function testTaggedLocatorWithDefaultPriorityMethodConfiguredViaAttribute
623623
// We need to check priority of instances in the factories
624624
$factories = (new \ReflectionClass($locator))->getProperty('factories');
625625

626-
self::assertSame([BarTagClass::class, FooTagClass::class], array_keys($factories->getValue($locator)));
626+
self::assertSame([FooTagClass::class, BarTagClass::class], array_keys($factories->getValue($locator)));
627627
}
628628

629629
public function testTaggedLocatorWithDefaultIndexMethodAndWithDefaultPriorityMethodConfiguredViaAttribute()
@@ -652,7 +652,7 @@ public function testTaggedLocatorWithDefaultIndexMethodAndWithDefaultPriorityMet
652652
// We need to check priority of instances in the factories
653653
$factories = (new \ReflectionClass($locator))->getProperty('factories');
654654

655-
self::assertSame(['bar_tag_class', 'foo_tag_class'], array_keys($factories->getValue($locator)));
655+
self::assertSame(['foo_tag_class', 'bar_tag_class'], array_keys($factories->getValue($locator)));
656656
self::assertSame($container->get(BarTagClass::class), $locator->get('bar_tag_class'));
657657
self::assertSame($container->get(FooTagClass::class), $locator->get('foo_tag_class'));
658658
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public static function getSubscribedServices(): array
462462
'autowired' => new ServiceClosureArgument(new TypedReference('service.id', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'autowired', [new Autowire(service: 'service.id')])),
463463
'autowired.nullable' => new ServiceClosureArgument(new TypedReference('service.id', 'stdClass', ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'autowired.nullable', [new Autowire(service: 'service.id')])),
464464
'autowired.parameter' => new ServiceClosureArgument('foobar'),
465-
'autowire.decorated' => new ServiceClosureArgument(new Reference('.service_locator.oO4rxCy.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE)),
465+
'autowire.decorated' => new ServiceClosureArgument(new Reference('.service_locator.0tSxobl.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE)),
466466
'target' => new ServiceClosureArgument(new TypedReference('stdClass', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'target', [new Target('someTarget')])),
467467
];
468468
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));

src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function testDefinitionOrderIsTheSame()
214214
$locator = $container->getDefinition($locator);
215215
$factories = $locator->getArguments()[0];
216216

217-
static::assertSame(['service-1', 'service-2'], array_keys($factories));
217+
static::assertSame(['service-2', 'service-1'], array_keys($factories));
218218
}
219219

220220
public function testBindingsAreProcessed()

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public function isCompiled(): bool
4343
public function getRemovedIds(): array
4444
{
4545
return [
46-
'.service_locator.2hyyc9y' => true,
47-
'.service_locator.KGUGnmw' => true,
48-
'.service_locator.KGUGnmw.foo_service' => true,
46+
'.service_locator.0H1ht0q' => true,
47+
'.service_locator.0H1ht0q.foo_service' => true,
48+
'.service_locator.tfSHZa1' => true,
4949
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true,
5050
];
5151
}
@@ -68,14 +68,14 @@ protected static function getTestServiceSubscriberService($container)
6868
protected static function getFooServiceService($container)
6969
{
7070
return $container->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...), [
71-
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
7271
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
72+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
7373
'bar' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
7474
'baz' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
7575
'late_alias' => ['services', 'late_alias', 'getLateAliasService', false],
7676
], [
77-
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
7877
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber',
78+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
7979
'bar' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
8080
'baz' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
8181
'late_alias' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestDefinition1',

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