diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index a97d22b8bf217817527fe8aac31ec604d93d8507..eef021e4564d80941c33e6965f1dbdfeb611a312 100755 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -3754,43 +3754,32 @@ class GeneralUtility } /** + * This method should be avoided, as it will be deprecated soon. Instead use makeInstance() directly. + * * Creates and returns reference to a user defined object. * This function can return an object reference if you like. - * Just prefix the function call with "&": "$objRef = &\TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj('EXT:myext/class.tx_myext_myclass.php:&tx_myext_myclass');". - * This will work ONLY if you prefix the class name with "&" as well. See description of function arguments. - * - * @todo Deprecate the whole method in several steps: - * 1. Deprecated singleton pattern (was removed in TYPO3 CMS 8) - * 2. Deprecate file prefix/ require file, - * 3. Deprecate usage without valid class name. - * 4. The last step should be to deprecate the method itself. * - * @param string $classRef Class reference, '[file-reference":"]["&"]class-name'. You can prefix the class name with "[file-reference]:" and \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName() will then be used to resolve the filename and subsequently include it by "require_once()" which means you don't have to worry about including the class file either! Example: "EXT:realurl/class.tx_realurl.php:&tx_realurl". Finally; for the class name you can prefix it with "&" and you will reuse the previous instance of the object identified by the full reference string (meaning; if you ask for the same $classRef later in another place in the code you will get a reference to the first created one!). + * @param string $classRef Class reference, '[file-reference":"]class-name'. You can prefix the class name with "[file-reference]:" and \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName() will then be used to resolve the filename and subsequently include it by "require_once()" which means you don't have to worry about including the class file either! Example: "EXT:realurl/class.tx_realurl.php:tx_realurl". * @return object The instance of the class asked for. Instance is created with \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance * @see callUserFunction() */ public static function getUserObj($classRef) { - // Check persistent object and if found, call directly and exit. - if (is_object($GLOBALS['T3_VAR']['getUserObj'][$classRef])) { - return $GLOBALS['T3_VAR']['getUserObj'][$classRef]; - } else { - // Check file-reference prefix; if found, require_once() the file (should be library of code) - if (strpos($classRef, ':') !== false) { - list($file, $class) = self::revExplode(':', $classRef, 2); - $requireFile = self::getFileAbsFileName($file); - if ($requireFile) { - require_once $requireFile; - } - } else { - $class = $classRef; + // Check file-reference prefix; if found, require_once() the file (should be library of code) + if (strpos($classRef, ':') !== false) { + list($file, $class) = self::revExplode(':', $classRef, 2); + $requireFile = self::getFileAbsFileName($file); + if ($requireFile) { + require_once $requireFile; } + } else { + $class = $classRef; + } - // Check if class exists: - if (class_exists($class)) { - $classObj = self::makeInstance($class); - return $classObj; - } + // Check if class exists: + if (class_exists($class)) { + $classObj = self::makeInstance($class); + return $classObj; } } diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php index b7ce5ca2483b58fcc5f4c2568ea481a3c4b688ac..3215d2a873e483a482daeaef1e0328c7adfe44cf 100644 --- a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php +++ b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php @@ -361,7 +361,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $hookMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandlerCheckModifyAccessListHookInterface::class, array('checkModifyAccessList'), array(), $hookClass); $hookMock->expects($this->once())->method('checkModifyAccessList'); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass; - $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock; + GeneralUtility::addInstance($hookClass, $hookMock); $this->subject->checkModifyAccessList('tt_content'); } @@ -460,7 +460,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $hookMock = $this->getMock($hookClass, array('checkFlexFormValue_beforeMerge')); $hookMock->expects($this->once())->method('checkFlexFormValue_beforeMerge'); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'][] = $hookClass; - $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock; + GeneralUtility::addInstance($hookClass, $hookMock); $this->subject->_call('checkValueForFlex', [], [], [], '', 0, '', '', 0, 0, 0, [], ''); } diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index d5cf253d48baaaf5c52409db46ee7f5f650e75c1..4572f2b5d77e5f119049de1d3538f289b7a10630 100755 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -3518,7 +3518,7 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $className = $this->getUniqueId('tx_coretest_getImageSourceCollectionHookCalled'); $getImageSourceCollectionHookMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectOneSourceCollectionHookInterface::class, array('getOneSourceCollection'), array(), $className); - $GLOBALS['T3_VAR']['getUserObj'][$className] = $getImageSourceCollectionHookMock; + GeneralUtility::addInstance($className, $getImageSourceCollectionHookMock); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'][] = $className; $getImageSourceCollectionHookMock diff --git a/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php b/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php index 0811c52c602a281a6f1722daf7b8c3bf0f2c4200..816c758166f43b8b7afd21a84e55b511d504f0eb 100644 --- a/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Page/PageRepositoryTest.php @@ -13,6 +13,7 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Page; * * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Test case @@ -64,7 +65,7 @@ class PageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $className = $this->getUniqueId('tx_coretest'); $getPageHookMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepositoryGetPageHookInterface::class, array('getPage_preProcess'), array(), $className); // Register hook mock object - $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock; + GeneralUtility::addInstance($className, $getPageHookMock); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className; // Test if hook is called and register a callback method to check given arguments $getPageHookMock->expects($this->once())->method('getPage_preProcess')->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback'))); diff --git a/typo3/sysext/frontend/Tests/Unit/View/AdminPanelViewTest.php b/typo3/sysext/frontend/Tests/Unit/View/AdminPanelViewTest.php index d3b31fe5cd112ec93b61c5aeab81ce0fc80e3a44..9e5e14aa7de3db843e4eb6367117a89513689d2a 100644 --- a/typo3/sysext/frontend/Tests/Unit/View/AdminPanelViewTest.php +++ b/typo3/sysext/frontend/Tests/Unit/View/AdminPanelViewTest.php @@ -13,6 +13,7 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\View; * * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Test case @@ -72,7 +73,7 @@ class AdminPanelViewTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $hookClass = $this->getUniqueId('tx_coretest'); $hookMock = $this->getMock(\TYPO3\CMS\Frontend\View\AdminPanelViewHookInterface::class, array(), array(), $hookClass); - $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock; + GeneralUtility::addInstance($hookClass, $hookMock); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = $hookClass; /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */ $adminPanelMock = $this->getMock(\TYPO3\CMS\Frontend\View\AdminPanelView::class, array('extGetLL'), array(), '', false);