10000 Allow decoration of service locators · symfony/symfony@1edaed2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1edaed2

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

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
10000 new ResolveChildDefinitionsPass(),
5454
new RegisterServiceSubscribersPass(),
55-
new DecoratorServicePass(),
5655
new ResolveParameterPlaceHoldersPass(false),
57-
new ResolveFactoryClassPass(),
5856
new ResolveNamedArgumentsPass(),
59-
new AutowireRequiredMethodsPass(),
6057
new ResolveBindingsPass(),
6158
new ServiceLocatorTagPass(),
6259
new CheckDefinitionValidityPass(),
60+
new DecoratorServicePass(),
61+
new ResolveFactoryClassPass(),
62+
new AutowireRequiredMethodsPass(),
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)
0