Commit 5c8d0397 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[TASK] Deprecate extbase ObjectManager

With all non-legacy usages of ObjectManager being gone,
this final patch adds a series of @deprecation annotations
throughout the core, adapts some comments, and finally
adds a trigger_error() to ObjectManager->get().

Resolves: #94619
Related: #90803
Releases: master
Change-Id: Iaa65f7dee4e5aa9eb4e2c217e76105b0263dc6dc
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70054

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
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 6e75da76
......@@ -3215,12 +3215,6 @@ class GeneralUtility
* You can also pass arguments for a constructor:
* \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\myClass::class, $arg1, $arg2, ..., $argN)
*
* You may want to use \TYPO3\CMS\Extbase\Object\ObjectManager::get() if you
* want TYPO3 to take care about injecting dependencies of the class to be
* created. Therefore create an instance of ObjectManager via
* GeneralUtility::makeInstance() first and call its get() method to get
* the instance of a specific class.
*
* @param string $className name of the class to instantiate, must not be empty and not start with a backslash
* @param array<int, mixed> $constructorArguments Arguments for the constructor
* @return object the created instance
......
.. include:: ../../Includes.txt
.. _changelog-Deprecation-90803-ObjectManagerGet:
===========================================================
Deprecation: #90803 - ObjectManager::get in Extbase context
===========================================================
......
.. include:: ../../Includes.txt
===========================================
Deprecation: #94619 - Extbase ObjectManager
===========================================
See :issue:`94619`
Description
===========
The extbase ObjectManager as the legacy core object lifecycle and
dependency injection solution has been marked discouraged with core v10 and
its introduction of the symfony based dependency injection solution already.
The v11 core no longer uses the extbase ObjectManager - only in a couple
of places as fallback for non-core extensions. The entire construct has now
been marked deprecated and will be removed with v12:
* :php:`TYPO3\CMS\Extbase\Object\ObjectManagerInterface` - Main interface
* :php:`TYPO3\CMS\Extbase\Object\ObjectManager` - Main implementation
* :php:`TYPO3\CMS\Extbase\Object\Container\Container` - Internal lifecycle management
* :php:`TYPO3\CMS\Extbase\Object\Exception` - Base exception
* :php:`TYPO3\CMS\Extbase\Object\Exception\CannotBuildObjectException` - Detail exception
* :php:`TYPO3\CMS\Extbase\Object\Container\Exception\CannotReconstituteObjectException` - Detail exception
* :php:`TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException` - Detail exception
* :php:`TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException` - Detail exception, obsolete
by deprecation of extbase signal slot dispatcher already.
* :php:`TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException` - Detail exception, obsolete
by deprecation of extbase signal slot dispatcher already.
Impact
======
Directly or indirectly calling :php:`ObjectManager->get()` will log a deprecation
level log entry.
Affected Installations
======================
Extensions that have been properly cleaned up for core v10 compatibility are not affected.
Extensions still relying on extbase ObjectManager are strongly encouraged to
switch to :php:`GeneralUtility::makeInstance()` and symfony based DI instead.
The extension scanner will find usages of the above classes and interfaces and shows
them as deprecated with a strong match.
Migration
=========
Documentation of migration paths have been established with core v10
documentation already. The :ref:`TYPO3 explained dependency injection section<t3coreapi:DependencyInjection>`
and the :ref:`ObjectManager->get() v10 changelog entry <changelog-Deprecation-90803-ObjectManagerGet>`
are especially helpful.
.. index:: PHP-API, FullyScanned, ext:extbase
......@@ -143,6 +143,7 @@ abstract class ActionController implements ControllerInterface
/**
* @var ObjectManagerInterface
* @internal only to be used within Extbase, not part of TYPO3 Core API.
* @deprecated since v11, will be removed in v12
*/
protected $objectManager;
......@@ -217,16 +218,19 @@ abstract class ActionController implements ControllerInterface
*
* @param ObjectManagerInterface $objectManager
* @internal only to be used within Extbase, not part of TYPO3 Core API.
* @deprecated since v11, will be removed in v12
*/
public function injectObjectManager(ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
// @todo: Move elsewhere
$this->arguments = GeneralUtility::makeInstance(Arguments::class);
}
/**
* @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
* @internal only to be used within Extbase, not part of TYPO3 Core API.
* @deprecated since v11, will be removed in v12
*/
public function injectSignalSlotDispatcher(Dispatcher $signalSlotDispatcher)
{
......
......@@ -38,6 +38,7 @@ class Dispatcher implements SingletonInterface
{
/**
* @var ObjectManagerInterface A reference to the object manager
* @deprecated since v11, will be removed in v12
*/
protected $objectManager;
......@@ -68,6 +69,7 @@ class Dispatcher implements SingletonInterface
ContainerInterface $container,
EventDispatcherInterface $eventDispatcher
) {
// @deprecated since v11, will be removed in v12
$this->objectManager = $objectManager;
$this->container = $container;
$this->eventDispatcher = $eventDispatcher;
......
......@@ -33,6 +33,9 @@ use TYPO3\CMS\Extbase\Reflection\ReflectionService;
/**
* Internal TYPO3 Dependency Injection container
* @internal only to be used within Extbase, not part of TYPO3 Core API.
* @deprecated since v11, will be removed in v12. Use symfony DI and GeneralUtility::makeInstance() instead.
* See TYPO3 explained documentation for more information.
* Does not trigger_error since the ObjectManager->get() call does that.
*/
class Container implements SingletonInterface, LoggerAwareInterface
{
......
......@@ -21,6 +21,8 @@ use TYPO3\CMS\Extbase\Object\Exception;
/**
* "Unknown Object" Exception
*
* @deprecated since v11, will be removed in v12. Drop along with ObjectManager / Container.
*/
class UnknownObjectException extends Exception
{
......
......@@ -21,6 +21,8 @@ use TYPO3\CMS\Extbase\Exception as ExtbaseException;
/**
* A generic Object Exception
*
* @deprecated since v11, will be removed in v12. Drop along with ObjectManager / Container.
*/
class Exception extends ExtbaseException
{
......
......@@ -21,6 +21,8 @@ use TYPO3\CMS\Extbase\Object\Exception;
/**
* "Cannot build object" Exception
*
* @deprecated since v11, will be removed in v12. Drop along with ObjectManager / Container.
*/
class CannotBuildObjectException extends Exception
{
......
......@@ -21,6 +21,8 @@ use TYPO3\CMS\Extbase\Object\Exception;
/**
* "Cannot reconstitute object" Exception
*
* @deprecated since v11, will be removed in v12. Drop along with ObjectManager / Container.
*/
class CannotReconstituteObjectException extends Exception
{
......
......@@ -23,6 +23,9 @@ use TYPO3\CMS\Extbase\Object\Container\Container as ExtbaseContainer;
/**
* Implementation of the default Extbase Object Manager
*
* @deprecated since v11, will be removed in v12. Use symfony DI and GeneralUtility::makeInstance() instead.
* See TYPO3 explained documentation for more information.
*/
class ObjectManager implements ObjectManagerInterface
{
......@@ -94,8 +97,7 @@ class ObjectManager implements ObjectManagerInterface
*/
public function get(string $objectName, ...$constructorArguments): object
{
// todo: This method needs to trigger a deprecation error as soon as the core does not use this method any more.
trigger_error('Class ' . __CLASS__ . ' is deprecated and will be removed in TYPO3 12.0', E_USER_DEPRECATED);
if ($objectName === \DateTime::class) {
return GeneralUtility::makeInstance($objectName, ...$constructorArguments);
}
......
......@@ -21,6 +21,9 @@ use TYPO3\CMS\Core\SingletonInterface;
/**
* Interface for the TYPO3 Object Manager
*
* @deprecated since v11, will be removed in v12. Use symfony DI and GeneralUtility::makeInstance() instead.
* See TYPO3 explained documentation for more information.
*/
interface ObjectManagerInterface extends SingletonInterface
{
......
......@@ -53,6 +53,7 @@ class DataMapper
protected Session $persistenceSession;
protected DataMapFactory $dataMapFactory;
protected QueryFactoryInterface $queryFactory;
// @deprecated since v11, will be removed in v12
protected ObjectManagerInterface $objectManager;
protected EventDispatcherInterface $eventDispatcher;
......
......@@ -34,6 +34,7 @@ class Repository implements RepositoryInterface, SingletonInterface
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
* @deprecated since v11, will be removed in v12
*/
protected $objectManager;
......@@ -70,6 +71,7 @@ class Repository implements RepositoryInterface, SingletonInterface
*/
public function __construct(ObjectManagerInterface $objectManager)
{
// @deprecated since v11, will be removed in v12
$this->objectManager = $objectManager;
$this->objectType = ClassNamingUtility::translateRepositoryNameToModelName($this->getRepositoryClassName());
}
......
......@@ -55,12 +55,14 @@ abstract class AbstractTypeConverter implements TypeConverterInterface, Singleto
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
* @deprecated since v11, will be removed in v12
*/
protected $objectManager;
/**
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
* @internal only to be used within Extbase, not part of TYPO3 Core API.
* @deprecated since v11, will be removed in v12
*/
public function injectObjectManager(ObjectManagerInterface $objectManager): void
{
......
......@@ -37,7 +37,9 @@ class ServiceProvider extends AbstractServiceProvider
public function getFactories(): array
{
return [
// @deprecated since v11, will be removed in v12
Object\Container\Container::class => [ static::class, 'getObjectContainer' ],
// @deprecated since v11, will be removed in v12
Object\ObjectManager::class => [ static::class, 'getObjectManager' ],
// @deprecated since v11, will be removed in v12
SignalSlot\Dispatcher::class => [ static::class, 'getSignalSlotDispatcher' ],
......@@ -52,16 +54,25 @@ class ServiceProvider extends AbstractServiceProvider
];
}
/**
* @deprecated since v11, will be removed in v12
*/
public static function getObjectContainer(ContainerInterface $container): Object\Container\Container
{
return self::new($container, Object\Container\Container::class, [$container]);
}
/**
* @deprecated since v11, will be removed in v12
*/
public static function getObjectManager(ContainerInterface $container): Object\ObjectManager
{
return self::new($container, Object\ObjectManager::class, [$container, $container->get(Object\Container\Container::class)]);
}
/**
* @deprecated since v11, will be removed in v12
*/
public static function getSignalSlotDispatcher(ContainerInterface $container): SignalSlot\Dispatcher
{
$logger = $container->get(LogManager::class)->getLogger(SignalSlot\Dispatcher::class);
......
......@@ -21,6 +21,8 @@ use TYPO3\CMS\Extbase\Object\Exception;
/**
* "Invalid Slot" Exception
*
* @deprecated since v11, will be removed in v12. Drop along with ObjectManager / Container.
*/
class InvalidSlotException extends Exception
{
......
......@@ -21,6 +21,8 @@ use TYPO3\CMS\Extbase\Object\Exception;
/**
* "Invalid Slot Return" Exception
*
* @deprecated since v11, will be removed in v12. Drop along with ObjectManager / Container.
*/
class InvalidSlotReturnException extends Exception
{
......
......@@ -33,6 +33,7 @@ return function (ContainerConfigurator $containerConfigurator, ContainerBuilder
// 'aliasDefinitions' is a private property of the Symfony ContainerBuilder class
// but as 'alias' statements an not be tagged, that is the only way to retrieve
// these aliases to map them to the extbase container
// @deprecated since v11, will be removed in v12. Drop everything below.
$reflection = new \ReflectionClass(get_class($container));
$aliasDefinitions = $reflection->getProperty('aliasDefinitions');
$aliasDefinitions->setAccessible(true);
......
......@@ -11,6 +11,7 @@ services:
public: true
shared: false
# @deprecated since v11, will be removed in v12
TYPO3\CMS\Extbase\Object\ObjectManagerInterface:
alias: TYPO3\CMS\Extbase\Object\ObjectManager
......
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