[FEATURE] Allow different overriding of object mapping per plugin
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Thu, 29 Nov 2012 14:05:36 +0000 (15:05 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 8 Feb 2013 18:11:25 +0000 (19:11 +0100)
Currently the ObjectContainer has an array with a mapping of
class names to actual classes which allows the replacement
of objects via DI.

This mapping is set during the bootstrap process and uses the
typoscript settings in config.tx_extbase.objects which is too
strict. To be able to ovverride these settings for each plugin
extbase has to use 'CONFIGURATION_TYPE_FRAMEWORK' settings
instead of 'CONFIGURATION_TYPE_FULL_TYPOSCRIPT' settings.

Releases: 6.1
Resolves: #44796
Change-Id: I5d6ea135f5bec586073da3394f0ba8e0197020b7
Reviewed-on: https://review.typo3.org/17696
Reviewed-by: Mattias Nilsson
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Classes/Core/Bootstrap.php
typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php [new file with mode: 0644]

index 51816ca..c0e7f71 100644 (file)
@@ -130,18 +130,18 @@ class Bootstrap implements \TYPO3\CMS\Extbase\Core\BootstrapInterface {
 
        /**
         * Configures the object manager object configuration from
-        * config.tx_extbase.objects
+        * config.tx_extbase.objects and plugin.tx_foo.objects
         *
         * @return void
         * @see initialize()
         */
        public function configureObjectManager() {
-               $typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
-               if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
+               $frameworkSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+               if (!is_array($frameworkSetup['objects'])) {
                        return;
                }
                $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
-               foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
+               foreach ($frameworkSetup['objects'] as $classNameWithDot => $classConfiguration) {
                        if (isset($classConfiguration['className'])) {
                                $originalClassName = rtrim($classNameWithDot, '.');
                                $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
diff --git a/typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php b/typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php
new file mode 100644 (file)
index 0000000..3dd32a3
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Core;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Testcase for the Bootstrap object
+ *
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+class BootstrapTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var array A backup of registered singleton instances
+        */
+       protected $singletonInstances = array();
+
+       /**
+        * Sets up this testcase
+        */
+       public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+       }
+
+       public function tearDown() {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+       }
+
+       /**
+        * @test
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function configureObjectManagerRespectsOverridingOfAlternativeObjectRegistrationViaPluginConfiguration() {
+               /** @var $objectContainer \TYPO3\CMS\Extbase\Object\Container\Container|\PHPUnit_Framework_MockObject_MockObject */
+               $objectContainer = $this->getMock('TYPO3\CMS\Extbase\Object\Container\Container', array('registerImplementation'));
+               $objectContainer->expects($this->once())->method('registerImplementation')->with('TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface', 'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager');
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\CMS\Extbase\Object\Container\Container', $objectContainer);
+
+               $frameworkSettings['objects'] = array(
+                       'TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface.' => array(
+                               'className' => 'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager'
+                       )
+               );
+
+               /** @var $configurationManagerMock \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject */
+               $configurationManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array('getConfiguration'));
+               $configurationManagerMock->expects($this->any())->method('getConfiguration')->with('Framework')->will($this->returnValue($frameworkSettings));
+
+               /** @var $bootstrapMock \TYPO3\CMS\Extbase\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\Tx_Phpunit_Interface_AccessibleObject */
+               $bootstrapMock = $this->getAccessibleMock('TYPO3\CMS\Extbase\Core\Bootstrap', array('inject'));
+               $bootstrapMock->_set('objectManager', $this->objectManager);
+               $bootstrapMock->_set('configurationManager', $configurationManagerMock);
+               $bootstrapMock->configureObjectManager();
+       }
+}
+
+?>
\ No newline at end of file