[TASK] Deprecate path prefixes in callUserFunction and getUserObj 52/48352/5
authorBenni Mack <benni@typo3.org>
Sat, 28 May 2016 11:31:04 +0000 (13:31 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Sat, 28 May 2016 12:26:45 +0000 (14:26 +0200)
The possibility to call "GeneralUtility::callUserFunc()"
and "getUserObj()" with the first parameter containing the file reference
to the function or class separated by a colon is deprecated.

An example is "EXT:realurl/class.tx_realurl.php:tx_realurl->encodeSpURL".

Calling one of the methods above with this syntax now triggers a
deprecation message.

It is encouraged to use the common autoloading functionality of
composer or via the fallback autoloader by TYPO3 to achieve the
same functionality.

Resolves: #76345
Releases: master
Change-Id: Iaaa2f825d330681199f0b0928727b93bbd3c73a7
Reviewed-on: https://review.typo3.org/48352
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-76345-PathPrefixesInCallUserFunctionAndGetUserObj.rst [new file with mode: 0644]
typo3/sysext/dbal/ext_conf_template.txt
typo3/sysext/extensionmanager/Tests/Unit/Domain/Repository/ConfigurationItemRepositoryTest.php
typo3/sysext/saltedpasswords/ext_conf_template.txt

index fd295be..73c7229 100755 (executable)
@@ -3690,7 +3690,7 @@ class GeneralUtility
      * Calls a user-defined function/method in class
      * Such a function/method should look like this: "function proc(&$params, &$ref) {...}"
      *
-     * @param string $funcName Function/Method reference or Closure, '[file-reference":"]["&"]class/function["->"method-name]'. You can prefix this reference 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->encodeSpURL". Finally; you can prefix the class name with "&" if you want to reuse a former instance of the same object call ("singleton").
+     * @param string $funcName Function/Method reference or Closure, '[file-reference":"]["&"]class/function["->"method-name]'. You can prefix this reference 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->encodeSpURL". However, using file references has been marked as deprecated and should be avoided, instead use the autoloading mechanism in place directly. Finally; you can prefix the class name with "&" if you want to reuse a former instance of the same object call ("singleton").
      * @param mixed $params Parameters to be pass along (typically an array) (REFERENCE!)
      * @param mixed $ref Reference to be passed along (typically "$this" - being a reference to the calling object) (REFERENCE!)
      * @param string $_ Not used anymore since 6.0
@@ -3714,6 +3714,10 @@ class GeneralUtility
         }
         // Check file-reference prefix; if found, require_once() the file (should be library of code)
         if (strpos($funcName, ':') !== false) {
+            // @deprecated since TYPO3 v8, will be removed in v9
+            self::deprecationLog('Using file references to resolve "' . $funcName . '" has been deprecated in TYPO3 v8 '
+                . 'when calling GeneralUtility::callUserFunction(), make sure the class is available via the class loader. '
+                . 'This functionality will be removed in TYPO3 v9.');
             list($file, $funcRef) = self::revExplode(':', $funcName, 2);
             $requireFile = self::getFileAbsFileName($file);
             if ($requireFile) {
@@ -3794,14 +3798,24 @@ class GeneralUtility
      * Creates and returns reference to a user defined object.
      * This function can return an object reference if you like.
      *
-     * @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
+     * @param string $classRef Class reference, '[file-reference":"]class-name'.
+     *                         You can prefix the class name with "[file-reference]:" and
+     *                         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".
+     *                         However, the file reference part is marked as deprecated as the class loading mechanism
+     *                         via composer or the autoloading part of TYPO3 should be used instead.
+     * @return object The instance of the class asked for. Instance is created with GeneralUtility::makeInstance
      * @see callUserFunction()
      */
     public static function getUserObj($classRef)
     {
         // Check file-reference prefix; if found, require_once() the file (should be library of code)
         if (strpos($classRef, ':') !== false) {
+            // @deprecated since TYPO3 v8, will be removed in v9
+            self::deprecationLog('Using file references to resolve "' . $classRef . '" has been deprecated in TYPO3 v8 '
+                . 'when calling GeneralUtility::getUserObj(), make sure the class is available via the class loader. '
+                . 'This functionality will be removed in TYPO3 v9.');
             list($file, $class) = self::revExplode(':', $classRef, 2);
             $requireFile = self::getFileAbsFileName($file);
             if ($requireFile) {
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76345-PathPrefixesInCallUserFunctionAndGetUserObj.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76345-PathPrefixesInCallUserFunctionAndGetUserObj.rst
new file mode 100644 (file)
index 0000000..e33d5de
--- /dev/null
@@ -0,0 +1,34 @@
+======================================================================
+Deprecation: #76345 - Path prefixes in callUserFunction and getUserObj
+======================================================================
+
+Description
+===========
+
+The two methods ``GeneralUtility::callUserFunc()`` and ``GeneralUtility::getUserObj()`` allow the first parameter to
+contain a file reference to the function/class to be called if prefixed with a colon.
+
+An example would be ``EXT:myext/Classes/MyClass.php:Benni\Myext\MyClass`` for including the class.
+
+Having the reference to the actual file is not needed since the composer autoloading mechanism takes care
+of loading everything properly already since TYPO3 6.2.9.
+
+
+Impact
+======
+
+Calling one of the methods above with a file reference prepended to the class name / function name will
+trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any installation with a hook that is registered with the file prefix functionality.
+
+
+Migration
+=========
+
+Remove the file prefix when registering a hook and make use of the common autoloading functionality of
+composer or via the fallback autoloader by TYPO3 to achieve the same functionality automatically.
\ No newline at end of file
index 9988315..8860dcb 100644 (file)
@@ -1,6 +1,6 @@
   # cat=basic; type=boolean; label=LLL:EXT:dbal/Resources/Private/Language/locallang_em.xlf:dbal.config.sql_query.passthrough
 sql_query.passthrough=1
 
-  # cat=basic; type=user[EXT:dbal/Classes/ExtensionManager/MessageDisplay.php:TYPO3\CMS\Dbal\ExtensionManager\MessageDisplay->displayMessage];
+  # cat=basic; type=user[TYPO3\CMS\Dbal\ExtensionManager\MessageDisplay->displayMessage];
 Compatibility=
 
index d8a80ab..d600dd1 100644 (file)
@@ -214,12 +214,12 @@ class ConfigurationItemRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                     'cat' => 'basic',
                     'subcat_name' => 'enable',
                     'subcat' => 'a/enable/z',
-                    'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
+                    'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]',
                     'label' => 'Frontend configuration check',
                     'name' => 'checkConfigurationFE',
                     'value' => 0,
                     'default_value' => 0,
-                    'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend'
+                    'comparisonGeneric' => 'TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationFrontend'
                 )
             ),
             array(
@@ -227,12 +227,12 @@ class ConfigurationItemRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                     'cat' => 'basic',
                     'subcat_name' => 'enable',
                     'subcat' => 'a/enable/z',
-                    'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend]',
+                    'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend]',
                     'label' => 'Backend configuration check',
                     'name' => 'checkConfigurationBE',
                     'value' => 0,
                     'default_value' => 0,
-                    'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend'
+                    'comparisonGeneric' => 'TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->checkConfigurationBackend'
                 )
             ),
             array(
@@ -240,12 +240,12 @@ class ConfigurationItemRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                     'cat' => 'basic',
                     'subcat_name' => 'enable',
                     'subcat' => 'a/enable/z',
-                    'type' => 'user[EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE]',
+                    'type' => 'user[TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE]',
                     'label' => 'Hashing method for the frontend: Defines salted hashing method to use. Choose "Portable PHP password hashing" to stay compatible with other CMS (e.g. Drupal, Wordpress). Choose "MD5 salted hashing" to reuse TYPO3 passwords for OS level authentication (other servers could use TYPO3 passwords). Choose "Blowfish salted hashing" for advanced security to reuse passwords on OS level (Blowfish might not be supported on your system TODO).',
                     'name' => 'FE.saltedPWHashingMethod',
                     'value' => \TYPO3\CMS\Saltedpasswords\Salt\PhpassSalt::class,
                     'default_value' => \TYPO3\CMS\Saltedpasswords\Salt\PhpassSalt::class,
-                    'comparisonGeneric' => 'EXT:saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php:TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE'
+                    'comparisonGeneric' => 'TYPO3\\CMS\\Saltedpasswords\\Utility\\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE'
                 )
             )
         );
index 8249fc3..e6a1cc7 100644 (file)
@@ -1,19 +1,19 @@
-# cat=Basic/enable; type=user[EXT:saltedpasswords/Classes/Utility/ExtensionManagerConfigurationUtility.php:TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationFE
+# cat=Basic/enable; type=user[TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationFE
 checkConfigurationFE=0
 
-# cat=Basic/enable; type=user[EXT:saltedpasswords/Classes/Utility/ExtensionManagerConfigurationUtility.php:TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationBackend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationBE
+# cat=Basic/enable; type=user[TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationBackend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationBE
 checkConfigurationBE=0
 
 # cat=Basic/enable; type=boolean; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.FE.enabled
 FE.enabled = 1
 
-# cat=Basic/enable; type=user[EXT:saltedpasswords/Classes/Utility/ExtensionManagerConfigurationUtility.php:TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.FE.saltedPWHashingMethod
+# cat=Basic/enable; type=user[TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->buildHashMethodSelectorFE]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.FE.saltedPWHashingMethod
 FE.saltedPWHashingMethod = tx_saltedpasswords_salts_phpass
 
-# cat=Basic/enable; type=user[EXT:saltedpasswords/Classes/Utility/ExtensionManagerConfigurationUtility.php:TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->buildHashMethodSelectorBE]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.BE.saltedPWHashingMethod
+# cat=Basic/enable; type=user[TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->buildHashMethodSelectorBE]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.BE.saltedPWHashingMethod
 BE.saltedPWHashingMethod = tx_saltedpasswords_salts_phpass
 
-# cat=Frontend; type=user[EXT:saltedpasswords/Classes/Utility/ExtensionManagerConfigurationUtility.php:TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationFE2
+# cat=Frontend; type=user[TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationFrontend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationFE2
 checkConfigurationFE2=0
 
 # cat=Frontend; type=boolean; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.FE.forceSalted
@@ -25,7 +25,7 @@ FE.onlyAuthService = 0
 # cat=Frontend; type=boolean; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.FE.updatePasswd
 FE.updatePasswd = 1
 
-# cat=Backend; type=user[EXT:saltedpasswords/Classes/Utility/ExtensionManagerConfigurationUtility.php:TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationBackend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationBE2
+# cat=Backend; type=user[TYPO3\CMS\Saltedpasswords\Utility\ExtensionManagerConfigurationUtility->checkConfigurationBackend]; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.checkConfigurationBE2
 checkConfigurationBE2=0
 
 # cat=Backend; type=boolean; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.BE.forceSalted
@@ -35,4 +35,4 @@ BE.forceSalted = 0
 BE.onlyAuthService = 0
 
 # cat=Backend; type=boolean; label=LLL:EXT:saltedpasswords/Resources/Private/Language/locallang_em.xlf:saltedpasswords.config.BE.updatePasswd
-BE.updatePasswd = 1
\ No newline at end of file
+BE.updatePasswd = 1