Skip to content

Commit c67c2df

Browse files
committed
Sort services in service locator according to priority
1 parent c0e7f09 commit c67c2df

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public static function register(ContainerBuilder $container, array $refMap, stri
102102
}
103103
$refMap[$id] = new ServiceClosureArgument($ref);
104104
}
105-
ksort($refMap);
106105

107106
$locator = (new Definition(ServiceLocator::class))
108107
->addArgument($refMap)

src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ function tagged_iterator(string $tag, string $indexAttribute = null, string $def
174174
/**
175175
* Creates a service locator by tag name.
176176
*/
177-
function tagged_locator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null): ServiceLocatorArgument
177+
function tagged_locator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null, string $defaultPriorityMethod = null): ServiceLocatorArgument
178178
{
179-
return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true));
179+
return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod));
180180
}
181181

182182
/**

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ public function testIndexedByServiceIdWithDecoration()
177177
static::assertFalse($locator->has(Decorated::class));
178178
static::assertInstanceOf(Decorated::class, $locator->get(Service::class));
179179
}
180+
181+
public function testDefinitionOrderIsTheSame()
182+
{
183+
$container = new ContainerBuilder();
184+
$container->register('service-1');
185+
$container->register('service-2');
186+
187+
$locator = ServiceLocatorTagPass::register($container, [
188+
'service-2' => new Reference('service-2'),
189+
'service-1' => new Reference('service-1'),
190+
]);
191+
$locator = $container->getDefinition($locator);
192+
$factories = $locator->getArguments()[0];
193+
194+
static::assertSame(['service-2', 'service-1'], array_keys($factories));
195+
}
180196
}
181197

182198
class Locator

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function isCompiled(): bool
4444
public function getRemovedIds(): array
4545
{
4646
return [
47-
'.service_locator.DlIAmAe' => true,
48-
'.service_locator.DlIAmAe.foo_service' => true,
4947
'.service_locator.t5IGRMW' => true,
48+
'.service_locator.zFfA7ng' => true,
49+
'.service_locator.zFfA7ng.foo_service' => true,
5050
'Psr\\Container\\ContainerInterface' => true,
5151
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
5252
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true,

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function testNoExceptionOnNonExistentTypeHintOptionalArg()
249249
$pass->process($container);
250250

251251
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
252-
$this->assertSame(['foo::barAction', 'foo::fooAction'], array_keys($locator));
252+
$this->assertEqualsCanonicalizing(['foo::barAction', 'foo::fooAction'], array_keys($locator));
253253
}
254254

255255
public function testArgumentWithNoTypeHintIsOk()
@@ -396,7 +396,10 @@ public function testAlias()
396396
$pass->process($container);
397397

398398
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
399-
$this->assertSame([RegisterTestController::class.'::fooAction', 'foo::fooAction'], array_keys($locator));
399+
400+
$services = array_keys($locator);
401+
sort($services);
402+
$this->assertSame([RegisterTestController::class.'::fooAction', 'foo::fooAction'], $services);
400403
}
401404

402405
/**

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testProcess()
5757
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing method "setTestCase" of service "c2" from controller candidates: the method is called at instantiation, thus cannot be an action.',
5858
];
5959

60-
$this->assertSame($expectedLog, $container->getCompiler()->getLog());
60+
$this->assertEqualsCanonicalizing($expectedLog, $container->getCompiler()->getLog());
6161
}
6262

6363
public function testInvoke()

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