[TASK] Deprecate custom singleton logic in GeneralUtility::getUserObj 16/40516/3
authorBenjamin Mack <benni@typo3.org>
Mon, 22 Jun 2015 05:52:13 +0000 (07:52 +0200)
committerNicole Cordes <typo3@cordes.co>
Thu, 25 Jun 2015 19:23:59 +0000 (21:23 +0200)
The prepending ampersand within GeneralUtility::getUserObj($className)
is marked for removal, as the SingletonInterface pattern should be used
in general for this approach as well.

Resolves: #67670
Releases: master
Change-Id: I7b6fbfdbcd668657ac66eba5f3b21361fbe7f5ac
Reviewed-on: http://review.typo3.org/40516
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Bernhard Kraft <kraftb@think-open.at>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Classes/Database/SoftReferenceIndex.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-67670-DeprecateCustomSingletonLogicInGeneralUtilitygetUserObj.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 6068013..4422466 100644 (file)
@@ -31,7 +31,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  * $softRefs = \TYPO3\CMS\Backend\Utility\BackendUtility::explodeSoftRefParserList($conf['softref']);          // Explode the list of softreferences/parameters
  * if ($softRefs !== FALSE) { // If there are soft references
  * foreach($softRefs as $spKey => $spParams)   {       // Traverse soft references
- * $softRefObj = &\TYPO3\CMS\Backend\Utility\BackendUtility::softRefParserObj($spKey); // create / get object
+ * $softRefObj = \TYPO3\CMS\Backend\Utility\BackendUtility::softRefParserObj($spKey);  // create / get object
  * if (is_object($softRefObj)) {       // If there was an object returned...:
  * $resultArray = $softRefObj->findRef($table, $field, $uid, $softRefValue, $spKey, $spParams);        // Do processing
  *
index d8b019a..9f95bd8 100755 (executable)
@@ -4192,9 +4192,10 @@ Connection: close
         * 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.
+        * Please note that the reference functionality is deprecated as of TYPO3 CMS 7, and will be removed with TYPO3 CMS 8, let the class use the SingletonInterface of TYPO3 instead.
         *
         * @todo Deprecate the whole method in several steps:
-        *      1. Deprecated singleton pattern,
+        *      1. Deprecated singleton pattern, (will be 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.
@@ -4220,6 +4221,11 @@ Connection: close
                        }
                        // Check for persistent object token, "&"
                        if ($class[0] === '&') {
+                               self::deprecationLog(
+                                       'The persistent functionality of getUserObj(), prepending the class name with & is deprecated since'
+                                       . ' TYPO3 CMS 7 and will be removed in TYPO3 CMS 8. To allow this functionality, implement '
+                                       . ' the \\TYPO3\\CMS\\Core\\SingletonInterface in the class "' . $classRef . '" instead.'
+                               );
                                $class = substr($class, 1);
                                $storePersistentObject = TRUE;
                        } else {
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-67670-DeprecateCustomSingletonLogicInGeneralUtilitygetUserObj.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-67670-DeprecateCustomSingletonLogicInGeneralUtilitygetUserObj.rst
new file mode 100644 (file)
index 0000000..c50e348
--- /dev/null
@@ -0,0 +1,51 @@
+====================================================================================
+Deprecation: #67670 - Deprecate custom singleton logic in GeneralUtility::getUserObj
+====================================================================================
+
+Description
+===========
+
+The functionality to allow to instantiate classes only once by calling ``GeneralUtility::getUserObj($className)`` multiple times while having a ``$className`` that is prepended with a ampersand ("&") has been marked for deprecation.
+
+
+An example of the deprecated behaviour in the ext_localconf.php of an extension:
+
+.. code-block:: php
+
+       $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['pi1_hooks']['getResultRows_SQLpointer'] = '&Acme\\MyExtension\\Hooks\\MysqlFulltextIndexHook';
+
+
+Impact
+======
+
+Any calls to ``GeneralUtility::getUserObj()`` with a prefixed ampersand will throw a deprecation message.
+
+
+Affected Installations
+======================
+
+TYPO3 Instances with extensions that use getUserObj() themselves and/or use hooks built with getUserObj() and use references.
+
+
+Migration
+=========
+
+Check if the classes that hook into certain parts of your custom extensions really need to be referenced / instantiated once. If so, implement the SingletonInterface of the TYPO3 Core, so the underlying function of ``GeneralUtility::makeInstance`` will register the SingletonInterface only once.
+
+The modified example from above now looks like this:
+
+.. code-block:: php
+
+       $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['pi1_hooks']['getResultRows_SQLpointer'] = \Acme\MyExtension\Hooks\MysqlFulltextIndexHook::class;
+
+
+While the class itself implements the SingletonInterface of the TYPO3 Core to only be instantiated once during a single request:
+
+.. code-block:: php
+
+       <?php
+       namespace \Acme\MyExtension\Hooks;
+
+       class MysqlFulltextIndexHook implements \TYPO3\CMS\Core\Core\SingletonInterface {
+               ...
+       }
index be79de4..1292e22 100644 (file)
@@ -2519,7 +2519,7 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function minifyJavaScriptCallsRegisteredHookWithInputString() {
                $hookClassName = $this->getUniqueId('tx_coretest');
                $minifyHookMock = $this->getMock('stdClass', array('minify'), array(), $hookClassName);
-               $functionName = '&' . $hookClassName . '->minify';
+               $functionName = $hookClassName . '->minify';
                $GLOBALS['T3_VAR']['callUserFunction'][$functionName] = array();
                $GLOBALS['T3_VAR']['callUserFunction'][$functionName]['obj'] = $minifyHookMock;
                $GLOBALS['T3_VAR']['callUserFunction'][$functionName]['method'] = 'minify';