Commit db551e17 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[BUGFIX] Extbase ObjectManager can inject PSR ContainerInterface

Legacy Extbase ObjectManager has a symfony DI compiler pass
that registers all DI registered "Foo"Interface aliases
via registerImplementation in Extbase container, too.

This however only works if the target is a class.
The Psr/Container/ContainerInterface is a magic
'service_container' alias, though. In turn, ObjectManager
fails to inject Psr/Container/ContainerInterface.

The patch adds this interface explicitly and adds a
functional test to make sure it works.

We target that patch to both v11 and v10 to simplify
the transition from ObjectManager to symfony based DI.

Resolves: #94608
Related: #90803
Related: #94453
Releases: master, 10.4
Change-Id: I282240548d8d8c571314dd433653dc30d1e0dad4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70017

Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent f61bbff9
......@@ -138,6 +138,10 @@ class Container implements SingletonInterface, LoggerAwareInterface
*/
protected function getInstanceInternal(string $className, ...$givenConstructorArguments): object
{
if ($className === ContainerInterface::class) {
return $this->psrContainer;
}
$className = $this->getImplementationClassName($className);
if ($givenConstructorArguments === [] && $this->psrContainer->has($className)) {
......
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Extbase\Tests\Functional\Object\Fixtures;
use Psr\Container\ContainerInterface;
class Test
{
public function __construct(ContainerInterface $container)
{
// Dummy to allow setting a breakpoint to this line.
$foo = 'bar';
}
}
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Extbase\Tests\Functional\Object;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
class ObjectManagerTest extends FunctionalTestCase
{
/**
* @test
*/
public function objectManagerCanInjectPsrContainerInterface(): void
{
$subject = $this->getContainer()->get(ObjectManager::class);
$subject->get(Fixtures\Test::class);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment