[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)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 15 Dec 2012 13:13:23 +0000 (14:13 +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: #43450
Change-Id: I067b19769e007578cea406964fc568dcf5727b7a
Reviewed-on: https://review.typo3.org/16855
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Core/Bootstrap.php
typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php [new file with mode: 0644]

index 8e75835..3eed780 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.'])) {
+               $typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+               if (!is_array($typoScriptSetup['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 ($typoScriptSetup['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..b80c08f
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Core;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  This class is a backport of the corresponding class 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!
+ ***************************************************************/
+class BootstrapTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Core\Bootstrap|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
+        */
+       protected $bootstrapMock;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
+        */
+       protected $configurationManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManager
+        */
+       protected $objectManager;
+
+       /**
+        * @var array
+        */
+       protected $frameworkSettings = array();
+
+       /**
+        * Sets up this testcase
+        */
+       public function setUp() {
+               $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+
+               $this->configurationManager = $this->getAccessibleMock('TYPO3\CMS\Extbase\Configuration\ConfigurationManager', array('getConfiguration'));
+               $this->bootstrapMock = $this->getAccessibleMock('TYPO3\CMS\Extbase\Core\Bootstrap', array('inject'));
+               $this->bootstrapMock->_set('objectManager', $this->objectManager);
+       }
+
+       /**
+        * @test
+        * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+        */
+       public function pluginConfigurationAffectsAlternativeImplementationPropertyOfObjectContainer() {
+               $this->frameworkSettings['objects'] = array(
+                       'TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface' => array(
+                               'className' => 'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager'
+                       )
+               );
+
+               $this->configurationManager->expects($this->any())->method('getConfiguration')->with('Framework')->will($this->returnValue($this->frameworkSettings));
+               $this->bootstrapMock->_set('configurationManager', $this->configurationManager);
+               $this->bootstrapMock->configureObjectManager();
+
+               /** @var $objectContainer \TYPO3\CMS\Extbase\Object\Container\Container */
+               $objectContainer = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
+
+               $class = new \ReflectionClass(get_class($objectContainer));
+               $property = $class->getProperty('alternativeImplementation');
+               $property->setAccessible(TRUE);
+               $alternativeImplementation = $property->getValue($objectContainer);
+
+               $this->assertEquals(
+                       'TYPO3\CMS\Extbase\Persistence\Reddis\PersistenceManager',
+                       $alternativeImplementation['TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface']
+               );
+       }
+}
+
+?>
\ No newline at end of file