Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] Service locators can't be decorated #33670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public function __construct()
new ValidateEnvPlaceholdersPass(),
new ResolveChildDefinitionsPass(),
new RegisterServiceSubscribersPass(),
new DecoratorServicePass(),
new ResolveParameterPlaceHoldersPass(false),
new ResolveFactoryClassPass(),
new ResolveNamedArgumentsPass(),
new AutowireRequiredMethodsPass(),
new ResolveBindingsPass(),
new ServiceLocatorTagPass(),
new CheckDefinitionValidityPass(),
new DecoratorServicePass(),
new ResolveFactoryClassPass(),
new AutowireRequiredMethodsPass(),
new AutowirePass(false),
new ResolveTaggedIteratorArgumentPass(),
new ResolveServiceSubscribersPass(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass;
use Symfony\Contracts\Service\ServiceProviderInterface;

/**
* This class tests the integration of the different compiler passes.
Expand Down Expand Up @@ -142,6 +143,29 @@ public function testCanDecorateServiceSubscriber()
$this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class));
}

public function testCanDecorateServiceLocator()
{
$container = new ContainerBuilder();

$container->register('foo', 'stdClass')->setPublic(true);

$container->register(ServiceLocator::class)
->addTag('container.service_locator')
->setArguments([[new Reference('foo')]])
;

$container->register(DecoratedServiceLocator::class)
->setDecoratedService(ServiceLocator::class)
->setPublic(true)
->setArguments([new Reference(DecoratedServiceLocator::class.'.inner')])
;

$container->compile();

$this->assertInstanceOf(DecoratedServiceLocator::class, $container->get(DecoratedServiceLocator::class));
nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved
$this->assertSame($container->get('foo'), $container->get(DecoratedServiceLocator::class)->get('foo'));
}

/**
* @dataProvider getYamlCompileTests
*/
Expand Down Expand Up @@ -416,6 +440,34 @@ class DecoratedServiceSubscriber
{
}

class DecoratedServiceLocator implements ServiceProviderInterface
{
/**
* @var ServiceLocator
*/
private $locator;

public function __construct(ServiceLocator $locator)
{
$this->locator = $locator;
}

public function get($id)
{
return $this->locator->get($id);
}

public function has($id): bool
{
return $this->locator->has($id);
}

public function getProvidedServices(): array
{
return $this->locator->getProvidedServices();
}
}

class IntegrationTestStub extends IntegrationTestStubParent
{
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.