[TASK] Deprecate config.tx_extbase.objects and plugin.tx_%name%.objects 88/58288/5
authorBenjamin Franzke <bfr@qbus.de>
Sun, 16 Sep 2018 05:01:31 +0000 (07:01 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 17 Sep 2018 09:19:41 +0000 (11:19 +0200)
If we want to introduce a system wide container in v10,
the non deterministic behaviour of object (re)configurations
during runtime in extbase will be a problem.
Compiled containers like symfony DI do not allow runtime
reconfigurations.

Also the concept of per plugin overwrites is broken anyway,
and should therefore be dropped:
The "objects" configured through plugin.tx_%name%.objects
are are never reset, that means:
Plugin A might overwrite an object and plugin B will implictly use
that overriden class, despite not having configured that at all.
(depending on the fact whether plugin A is rendered before or not)

config.tx_extbase.object class overwrites can be replaced by XCLASSes.
If config.tx_extbase.object was/is used to conditionally overwrite
classes (through sys_template or conditions), these
occasions should be changed to XCLASSes as well. In that case the
conditional overwrite needs to be moved into the xclass itself.

Change-Id: I2ef839bcbb7f941c3afa0010767560d20e15f98b
Releases: master
Resolves: #86270
Reviewed-on: https://review.typo3.org/58288
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-86270-ExtbaseXclassViaTypoScriptSettings.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Core/Bootstrap.php
typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php [deleted file]
typo3/sysext/extbase/Tests/UnitDeprecated/Core/BootstrapTest.php [new file with mode: 0644]
typo3/sysext/fluid/Classes/Core/Widget/Bootstrap.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86270-ExtbaseXclassViaTypoScriptSettings.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86270-ExtbaseXclassViaTypoScriptSettings.rst
new file mode 100644 (file)
index 0000000..586f936
--- /dev/null
@@ -0,0 +1,36 @@
+.. include:: ../../Includes.txt
+
+==============================================================================
+Deprecation: #86270 - config.tx_extbase.objects and plugin.tx_%plugin%.objects
+==============================================================================
+
+See :issue:`86270`
+
+Description
+===========
+
+The :ts:`config.tx_extbase.objects` and :ts:`plugin.tx_%plugin%.objects` configuration options have been marked as deprecated.
+
+
+Impact
+======
+
+Configuring class overrides using :ts:`config.tx_extbase.objects` or :ts:`plugin.tx_%plugin%.objects` will log a
+deprecation warning.
+
+
+Affected Installations
+======================
+
+All installations that make use of the TypoScript :ts:`config.tx_extbase.objects` or :ts:`plugin.tx_%plugin%.objects`
+configuration options are affected.
+
+
+Migration
+=========
+
+Use XCLASSes configured through :php:`$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']` instead.
+If you conditionally configured :ts:`config.tx_extbase.objects` or
+:ts:`plugin.tx_%plugin%.objects`, then move that conditional logic into the XCLASS itself.
+
+.. index:: TypoScript, NotScanned, ext:extbase
index 392258d..13dbb32 100644 (file)
@@ -77,7 +77,7 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface
         }
         $this->initializeObjectManager();
         $this->initializeConfiguration($configuration);
-        $this->configureObjectManager();
+        $this->configureObjectManager(true);
         $this->initializePersistence();
     }
 
@@ -110,14 +110,20 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface
      * Configures the object manager object configuration from
      * config.tx_extbase.objects and plugin.tx_foo.objects
      *
+     * @param bool $isInternalCall Set to true by Boostrap, not by extensions
      * @see initialize()
+     * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
      */
-    public function configureObjectManager()
+    public function configureObjectManager($isInternalCall = false)
     {
+        if (!$isInternalCall) {
+            trigger_error(self::class . '::configureObjectManager() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
+        }
         $frameworkSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
         if (!isset($frameworkSetup['objects']) || !is_array($frameworkSetup['objects'])) {
             return;
         }
+        trigger_error('Overriding object implementations via TypoScript settings config.tx_extbase.objects and plugin.tx_%plugin%.objects will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
         $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
         foreach ($frameworkSetup['objects'] as $classNameWithDot => $classConfiguration) {
             if (isset($classConfiguration['className'])) {
diff --git a/typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php b/typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php
deleted file mode 100644 (file)
index 1cec66b..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Core;
-
-/*
- * 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!
- */
-
-use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
-
-/**
- * Test case
- */
-class BootstrapTest extends UnitTestCase
-{
-    /**
-     * @var bool Reset singletons created by subject
-     */
-    protected $resetSingletonInstances = true;
-
-    /**
-     * @test
-     */
-    public function configureObjectManagerRespectsOverridingOfAlternativeObjectRegistrationViaPluginConfiguration()
-    {
-        /** @var $objectContainer \TYPO3\CMS\Extbase\Object\Container\Container|\PHPUnit_Framework_MockObject_MockObject */
-        $objectContainer = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\Container\Container::class)
-            ->setMethods(['registerImplementation'])
-            ->getMock();
-        $objectContainer->expects($this->once())->method('registerImplementation')->with(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class, 'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager');
-        \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class, $objectContainer);
-
-        $frameworkSettings['objects'] = [
-            'TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface.' => [
-                'className' => 'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager'
-            ]
-        ];
-
-        /** @var $configurationManagerMock \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
-        $configurationManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class, ['getConfiguration']);
-        $configurationManagerMock->expects($this->any())->method('getConfiguration')->with('Framework')->will($this->returnValue($frameworkSettings));
-
-        /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject  $objectManager */
-        $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
-
-        /** @var $bootstrapMock \TYPO3\CMS\Extbase\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
-        $bootstrapMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Core\Bootstrap::class, ['inject']);
-        $bootstrapMock->_set('objectManager', $objectManager);
-        $bootstrapMock->_set('configurationManager', $configurationManagerMock);
-        $bootstrapMock->configureObjectManager();
-    }
-}
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Core/BootstrapTest.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Core/BootstrapTest.php
new file mode 100644 (file)
index 0000000..2e5c5f9
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Core;
+
+/*
+ * 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!
+ */
+
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Test case
+ */
+class BootstrapTest extends UnitTestCase
+{
+    /**
+     * @var bool Reset singletons created by subject
+     */
+    protected $resetSingletonInstances = true;
+
+    /**
+     * @test
+     */
+    public function configureObjectManagerRespectsOverridingOfAlternativeObjectRegistrationViaPluginConfiguration()
+    {
+        /** @var $objectContainer \TYPO3\CMS\Extbase\Object\Container\Container|\PHPUnit_Framework_MockObject_MockObject */
+        $objectContainer = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\Container\Container::class)
+            ->setMethods(['registerImplementation'])
+            ->getMock();
+        $objectContainer->expects($this->once())->method('registerImplementation')->with(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class, 'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager');
+        \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class, $objectContainer);
+
+        $frameworkSettings['objects'] = [
+            'TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface.' => [
+                'className' => 'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager'
+            ]
+        ];
+
+        /** @var $configurationManagerMock \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
+        $configurationManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class, ['getConfiguration']);
+        $configurationManagerMock->expects($this->any())->method('getConfiguration')->with('Framework')->will($this->returnValue($frameworkSettings));
+
+        /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject  $objectManager */
+        $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
+
+        /** @var $bootstrapMock \TYPO3\CMS\Extbase\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
+        $bootstrapMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Core\Bootstrap::class, ['inject']);
+        $bootstrapMock->_set('objectManager', $objectManager);
+        $bootstrapMock->_set('configurationManager', $configurationManagerMock);
+        $bootstrapMock->configureObjectManager();
+    }
+}
index e3e87e7..ee7053c 100644 (file)
@@ -46,7 +46,7 @@ class Bootstrap
     {
         $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $this->initializeConfiguration($configuration);
-        $this->configureObjectManager();
+        $this->configureObjectManager(true);
         $ajaxWidgetContextHolder = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder::class);
         $widgetIdentifier = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('fluid-widget-id');
         $widgetContext = $ajaxWidgetContextHolder->get($widgetIdentifier);
@@ -76,15 +76,20 @@ class Bootstrap
      * Configures the object manager object configuration from
      * config.tx_extbase.objects
      *
+     * @param $isInternalCall bool Set to true by Boostrap, not by extensions
      * @see initialize()
-     * @todo this is duplicated code (see \TYPO3\CMS\Extbase\Core\Bootstrap::configureObjectManager())
+     * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
      */
-    public function configureObjectManager()
+    public function configureObjectManager(bool $isInternalCall = false)
     {
+        if (!$isInternalCall) {
+            trigger_error(self::class . '->configureObjectManager() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
+        }
         $typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
         if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
             return;
         }
+        trigger_error('Overriding object implementations via TypoScript settings config.tx_extbase.objects and plugin.tx_%plugin%.objects will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
         $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
         foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
             if (isset($classConfiguration['className'])) {
index 6aeb48b..fd22e7a 100644 (file)
@@ -3390,4 +3390,18 @@ return [
             'Deprecation-86047-TSFEPropertiesMethodsAndChangeVisibility.rst',
         ],
     ],
+    'TYPO3\CMS\Extbase\Core\Bootstrap->configureObjectManager' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-86270-ExtbaseXclassViaTypoScriptSettings.rst',
+        ],
+    ],
+    'TYPO3\CMS\Fluid\Core\Widget\Bootstrap->configureObjectManager' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-86270-ExtbaseXclassViaTypoScriptSettings.rst',
+        ],
+    ],
 ];