Skip to content

Commit 37e99cc

Browse files
committed
Allow decoration of service locators
1 parent d835a8c commit 37e99cc

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public function __construct()
5252
new ValidateEnvPlaceholdersPass(),
5353
new ResolveChildDefinitionsPass(),
5454
new RegisterServiceSubscribersPass(),
55+
new ResolveBindingsPass(),
56+
new ServiceLocatorTagPass(),
57+
new CheckDefinitionValidityPass(),
5558
new DecoratorServicePass(),
5659
new ResolveParameterPlaceHoldersPass(false),
5760
new ResolveFactoryClassPass(),
5861
new ResolveNamedArgumentsPass(),
5962
new AutowireRequiredMethodsPass(),
60-
new ResolveBindingsPass(),
61-
new ServiceLocatorTagPass(),
62-
new CheckDefinitionValidityPass(),
6363
new AutowirePass(false),
6464
new ResolveTaggedIteratorArgumentPass(),
6565
new ResolveServiceSubscribersPass(),

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass;
2525
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedClass;
2626
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass;
27+
use Symfony\Contracts\Service\ServiceProviderInterface;
2728

2829
/**
2930
* This class tests the integration of the different compiler passes.
@@ -145,16 +146,24 @@ public function testCanDecorateServiceSubscriber()
145146
public function testCanDecorateServiceLocator()
146147
{
147148
$container = new ContainerBuilder();
149+
150+
$container->register('foo', 'stdClass')->setPublic(true);
151+
148152
$container->register(ServiceLocator::class)
149153
->addTag('container.service_locator')
154+
->setArguments([[new Reference('foo')]])
150155
;
151156

152157
$container->register(DecoratedServiceLocator::class)
153-
->setDecoratedService(ServiceLocator::class);
158+
->setDecoratedService(ServiceLocator::class)
159+
->setPublic(true)
160+
->setArguments([new Reference(DecoratedServiceLocator::class.'.inner')])
161+
;
154162

155163
$container->compile();
156164

157165
$this->assertInstanceOf(DecoratedServiceLocator::class, $container->get(DecoratedServiceLocator::class));
166+
$this->assertSame($container->get('foo'), $container->get(DecoratedServiceLocator::class)->get('foo'));
158167
}
159168

160169
/**
@@ -431,8 +440,32 @@ class DecoratedServiceSubscriber
431440
{
432441
}
433442

434-
class DecoratedServiceLocator
443+
class DecoratedServiceLocator implements ServiceProviderInterface
435444
{
445+
/**
446+
* @var ServiceLocator
447+
*/
448+
private $locator;
449+
450+
public function __construct(ServiceLocator $locator)
451+
{
452+
$this->locator = $locator;
453+
}
454+
455+
public function get($id)
456+
{
457+
return $this->locator->get($id);
458+
}
459+
460+
public function has($id): bool
461+
{
462+
return $this->locator->has($id);
463+
}
464+
465+
public function getProvidedServices(): array
466+
{
467+
return $this->locator->getProvidedServices();
468+
}
436469
}
437470

438471
class IntegrationTestStub extends IntegrationTestStubParent

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