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
......@@ -82,7 +82,8 @@ final class RenderingContextFactory
/** @var TemplateProcessorInterface[] $processors */
$processors[] = $this->container->get($className);
} else {
// @deprecated: Layer for processors that can't be instantiated by symfony-DI yet,
// @deprecated since v11, will be removed with 12.
// Layer for processors that can't be instantiated by symfony-DI yet,
// probably due to a missing Services.yaml in the providing extension. Fall back to ObjectManager,
// which logs a deprecation. If condition and else can be dropped in v12.
$objectManager = $this->container->get(ObjectManager::class);
......
......@@ -44,6 +44,7 @@ final class ViewHelperResolverFactory
ObjectManagerInterface $objectManager
) {
$this->container = $container;
// @deprecated since v11, will be removed with 12. Drop in fluid ServiceProvider.php, too.
$this->objectManager = $objectManager;
}
......
......@@ -53,6 +53,7 @@ class ServiceProvider extends AbstractServiceProvider
{
return self::new($container, Core\ViewHelper\ViewHelperResolverFactory::class, [
$container,
// @deprecated since v11, will be removed with 12.
$container->get(ObjectManager::class)
]);
}
......
......@@ -38,9 +38,9 @@ use TYPO3\CMS\Form\Domain\Model\FormDefinition;
* <pre>
* class MyFooBarFactory extends AbstractFormFactory {
* public function build(array $configuration, $prototypeName) {
* $configurationService = GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationService::class);
* $configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
* $prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
* $formDefinition = GeneralUtility::makeInstance(ObjectManager::class)->get(FormDefinition::class, 'nameOfMyForm', $prototypeConfiguration);
* $formDefinition = GeneralUtility::makeInstance(FormDefinition::class, 'nameOfMyForm', $prototypeConfiguration);
*
* // now, you should call methods on $formDefinition to add pages and form elements
*
......
......@@ -28,7 +28,7 @@ use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
*
* Usage:
* //...
* $closureFinisher = $this->objectManager->get(ClosureFinisher::class);
* $closureFinisher = GeneralUtility::makeInstance(ClosureFinisher::class);
* $closureFinisher->setOption('closure', function($finisherContext) {
* $formRuntime = $finisherContext->getFormRuntime();
* // ...
......
......@@ -35,7 +35,7 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
*
* Usage:
* //...
* $confirmationFinisher = $this->objectManager->get(ConfirmationFinisher::class);
* $confirmationFinisher = GeneralUtility::makeInstance(ConfirmationFinisher::class);
* $confirmationFinisher->setOptions(
* [
* 'message' => 'foo',
......
......@@ -37,7 +37,7 @@ use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
*
* Usage:
* //...
* $flashMessageFinisher = $this->objectManager->get(FlashMessageFinisher::class);
* $flashMessageFinisher = GeneralUtility::makeInstance(FlashMessageFinisher::class);
* $flashMessageFinisher->setOptions(
* [
* 'messageBody' => 'Some message body',
......
......@@ -110,6 +110,7 @@ class FormRuntime implements RootRenderableInterface, \ArrayAccess
const HONEYPOT_NAME_SESSION_IDENTIFIER = 'tx_form_honeypot_name_';
protected ContainerInterface $container;
// @deprecated since v11, will be removed in v12
protected ObjectManagerInterface $objectManager;
protected ?FormDefinition $formDefinition = null;
protected ?Request $request = null;
......
......@@ -228,7 +228,6 @@ Implement a ``FormFactory`` and build the form::
namespace VENDOR\MySitePackage\Domain\Factory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator;
use TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator;
use TYPO3\CMS\Form\Domain\Configuration\ConfigurationService;
......@@ -250,21 +249,21 @@ Implement a ``FormFactory`` and build the form::
public function build(array $configuration, string $prototypeName = null): FormDefinition
{
$prototypeName = 'standard';
$configurationService = GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationService::class);
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
$form = GeneralUtility::makeInstance(ObjectManager::class)->get(FormDefinition::class, 'MyCustomForm', $prototypeConfiguration);
$form = GeneralUtility::makeInstance(FormDefinition::class, 'MyCustomForm', $prototypeConfiguration);
$form->setRenderingOption('controllerAction', 'index');
$page1 = $form->createPage('page1');
$name = $page1->createElement('name', 'Text');
$name->setLabel('Name');
$name->addValidator(GeneralUtility::makeInstance(ObjectManager::class)->get(NotEmptyValidator::class));
$name->addValidator(GeneralUtility::makeInstance(NotEmptyValidator::class));
$page2 = $form->createPage('page2');
$message = $page2->createElement('message', 'Textarea');
$message->setLabel('Message');
$message->addValidator(GeneralUtility::makeInstance(ObjectManager::class)->get(StringLengthValidator::class, ['minimum' => 5, 'maximum' => 20]));
$message->addValidator(GeneralUtility::makeInstance(StringLengthValidator::class, ['minimum' => 5, 'maximum' => 20]));
// Creating a RadioButton/MultiCheckbox
$page3 = $form->createPage('page3');
......@@ -1717,7 +1716,7 @@ declare this finisher.
Usage through code::
$closureFinisher = $this->objectManager->get(ClosureFinisher::class);
$closureFinisher = GeneralUtility::makeInstance(ClosureFinisher::class);
$closureFinisher->setOption('closure', function($finisherContext) {
$formRuntime = $finisherContext->getFormRuntime();
// ...
......@@ -1776,7 +1775,7 @@ Usage through code::
or create manually (not preferred)::
$confirmationFinisher = $this->objectManager->get(ConfirmationFinisher::class);
$confirmationFinisher = GeneralUtility::makeInstance(ConfirmationFinisher::class);
$confirmationFinisher->setOptions([
'message' => 'foo',
]);
......@@ -1832,7 +1831,7 @@ Usage through code::
or create manually (not preferred)::
$deleteUploadsFinisher = $this->objectManager->get(DeleteUploadsFinisher::class);
$deleteUploadsFinisher = GeneralUtility::makeInstance(DeleteUploadsFinisher::class);
$formDefinition->addFinisher($deleteUploadsFinisher);
......@@ -1876,7 +1875,7 @@ Usage through code::
or create manually (not preferred)::
$emailFinisher = $this->objectManager->get(EmailFinisher::class);
$emailFinisher = GeneralUtility::makeInstance(EmailFinisher::class);
$emailFinisher->setOptions([
'subject' => 'Your message',
'recipientAddress' => 'your.company@example.com',
......@@ -2262,7 +2261,7 @@ Usage through code::
or create manually (not preferred)::
$flashMessageFinisher = $this->objectManager->get(FlashMessageFinisher::class);
$flashMessageFinisher = GeneralUtility::makeInstance(FlashMessageFinisher::class);
$flashMessageFinisher->setOptions([
'messageTitle' => 'Merci',
'messageCode' => 201905041245,
......@@ -2396,7 +2395,7 @@ Usage through code::
or create manually (not preferred)::
$redirectFinisher = $this->objectManager->get(RedirectFinisher::class);
$redirectFinisher = GeneralUtility::makeInstance(RedirectFinisher::class);
$redirectFinisher->setOptions([
'pageUid' => 1,
'additionalParameters' => 'param1=value1&param2=value2',
......@@ -2547,7 +2546,7 @@ Usage through code::
or create manually (not preferred)::
$saveToDatabaseFinisher = $this->objectManager->get(SaveToDatabaseFinisher::class);
$saveToDatabaseFinisher = GeneralUtility::makeInstance(SaveToDatabaseFinisher::class);
$saveToDatabaseFinisher->setOptions([
'table' => 'fe_users',
'mode' => 'update',
......@@ -2624,7 +2623,7 @@ Usage through code::
or create manually (not preferred)::
$saveToDatabaseFinisher = $this->objectManager->get(SaveToDatabaseFinisher::class);
$saveToDatabaseFinisher = GeneralUtility::makeInstance(SaveToDatabaseFinisher::class);
$saveToDatabaseFinisher->setOptions([
1 => [
'table' => 'my_table',
......
......@@ -61,13 +61,13 @@ Basically, you can manually create a ``FormDefinition`` domain model just
by calling the API methods on it, or you can use a ``FormFactory`` to build
the form from a different representation format such as YAML::
$formDefinition = $this->objectManager->get(FormDefinition::class, 'myForm');
$formDefinition = GeneralUtility::makeInstance(FormDefinition::class, 'myForm');
$page1 = $this->objectManager->get(Page::class, 'page1');
$page1 = GeneralUtility::makeInstance(Page::class, 'page1');
$formDefinition->addPage($page);
// second argument is the <formElementTypeIdentifier> of the form element
$element1 = $this->objectManager->get(GenericFormElement::class, 'title', 'Text');
$element1 = GeneralUtility::makeInstance(GenericFormElement::class, 'title', 'Text');
$page1->addElement($element1);
......@@ -91,7 +91,7 @@ shown above should be rewritten as follows::
// we will come back to this later on
$prototypeConfiguration = [];
$formDefinition = $this->objectManager->get(FormDefinition::class, 'myForm', $prototypeConfiguration);
$formDefinition = GeneralUtility::makeInstance(FormDefinition::class, 'myForm', $prototypeConfiguration);
$page1 = $formDefinition->createPage('page1');
$element1 = $page1->addElement('title', 'Text');
......
......@@ -821,8 +821,7 @@ class MaintenanceController extends AbstractController
// with some hacked settings to disable caching of extbase and fluid.
// We want a "fresh" object here to operate on a different cache setup.
// cacheManager implements SingletonInterface, so the only way to get a "fresh"
// instance is by circumventing makeInstance and/or the objectManager and
// using new directly!
// instance is by circumventing makeInstance and using new directly!
$cacheManager = new CacheManager();
$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
$cacheManager->getCache('l10n')->flush();
......
......@@ -1669,4 +1669,49 @@ return [
'Deprecation-94367-ExtbaseReferringRequest.rst'
],
],
'TYPO3\CMS\Extbase\Object\ObjectManager' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\Object\ObjectManagerInterface' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\Object\Container\Container' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\Object\Exception\CannotBuildObjectException' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\Object\Exception\CannotReconstituteObjectException' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\Object\Exception' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
'TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException' => [
'restFiles' => [
'Deprecation-94619-ExtbaseObjectManager.rst'
],
],
];
Supports Markdown
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