[TASK] Improve description for EidUtility deprecation
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Utility / EidUtility.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Utility;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Cache\CacheManager;
18 use TYPO3\CMS\Core\Localization\LanguageService;
19 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
22 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
23
24 /**
25 * Tools for scripts using the eID feature of the TYPO3 Frontend.
26 * Included from \TYPO3\CMS\Frontend\Http\RequestHandler.
27 * Since scripts using the eID feature does not
28 * have a full FE environment initialized by default
29 * this class seeks to provide functions that can
30 * initialize parts of the FE environment as needed,
31 * eg. Frontend User session, Database connection etc.
32 *
33 * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Ensure to migrate your eID script to a PSR-15 middleware at the right position, where the frontend is boot up at the level you need.
34 */
35 class EidUtility
36 {
37 /**
38 * Load and initialize Frontend User. Note, this process is slow because
39 * it creates a calls many objects. Call this method only if necessary!
40 *
41 * @return FrontendUserAuthentication Frontend User object (usually known as TSFE->fe_user)
42 * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Use the FrontendUserAuthenticator PSR-15 middleware to set up the Frontend User.
43 */
44 public static function initFeUser()
45 {
46 trigger_error('EidUtility::initFeUser() will be removed in TYPO3 v10. Use a PSR-15 middleware instead.', E_USER_DEPRECATED);
47 // Get TSFE instance. It knows how to initialize the user.
48 $tsfe = self::getTSFE();
49 $tsfe->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
50 // List of pid's acceptable
51 $pid = GeneralUtility::_GP('pid');
52 $tsfe->fe_user->checkPid_value = $pid ? implode(',', GeneralUtility::intExplode(',', $pid)) : 0;
53 // Check if a session is transferred:
54 if (GeneralUtility::_GP('FE_SESSION_KEY')) {
55 $fe_sParts = explode('-', GeneralUtility::_GP('FE_SESSION_KEY'));
56 // If the session key hash check is OK:
57 if (md5($fe_sParts[0] . '/' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) === (string)$fe_sParts[1]) {
58 $cookieName = FrontendUserAuthentication::getCookieName();
59 $_COOKIE[$cookieName] = $fe_sParts[0];
60 if (isset($_SERVER['HTTP_COOKIE'])) {
61 // See http://forge.typo3.org/issues/27740
62 $_SERVER['HTTP_COOKIE'] .= ';' . $cookieName . '=' . $fe_sParts[0];
63 }
64 $tsfe->fe_user->forceSetCookie = true;
65 $tsfe->fe_user->dontSetCookie = false;
66 unset($cookieName);
67 }
68 }
69 $tsfe->fe_user->start();
70 $tsfe->fe_user->unpack_uc();
71
72 // Call hook for possible manipulation of frontend user object
73 $_params = ['pObj' => &$tsfe];
74 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'] ?? [] as $_funcRef) {
75 GeneralUtility::callUserFunction($_funcRef, $_params, $tsfe);
76 }
77 // Return FE user object:
78 return $tsfe->fe_user;
79 }
80
81 /**
82 * Initializes $GLOBALS['LANG'] for use in eID scripts.
83 *
84 * @param string $language TYPO3 language code
85 * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Instantiate the LanguageService by yourself instead.
86 */
87 public static function initLanguage($language = 'default')
88 {
89 trigger_error('EidUtility::initLanguage() will be removed in TYPO3 v10. Ensure to intantiate the LanguageService by yourself.', E_USER_DEPRECATED);
90 if (!is_object($GLOBALS['LANG'])) {
91 $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
92 $GLOBALS['LANG']->init($language);
93 }
94 }
95
96 /**
97 * Makes TCA available inside eID
98 * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Is not needed anymore within eID scripts as TCA is now available at any time
99 */
100 public static function initTCA()
101 {
102 trigger_error('EidUtility::initTCA() will be removed in TYPO3 v10. Is not needed anymore within eID scripts as TCA is now available at any time.', E_USER_DEPRECATED);
103 // Some badly made extensions attempt to manipulate TCA in a wrong way
104 // (inside ext_localconf.php). Therefore $GLOBALS['TCA'] may become an array
105 // but in fact it is not loaded. The check below ensure that
106 // TCA is still loaded if such bad extensions are installed
107 if (!is_array($GLOBALS['TCA']) || !isset($GLOBALS['TCA']['pages'])) {
108 ExtensionManagementUtility::loadBaseTca();
109 }
110 }
111
112 /**
113 * Makes TCA for the extension available inside eID. Use this function if
114 * you need not to include the whole $GLOBALS['TCA'].
115 *
116 * @param string $extensionKey Extension key
117 * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0.
118 */
119 public static function initExtensionTCA($extensionKey)
120 {
121 trigger_error('EidUtility::initExtensionTCA() will be removed in TYPO3 v10 as it is discouraged to only load ext_tables.php of one extension. Use ExtensionManagementUtility instead.', E_USER_DEPRECATED);
122 $extTablesPath = ExtensionManagementUtility::extPath($extensionKey, 'ext_tables.php');
123 if (file_exists($extTablesPath)) {
124 $GLOBALS['_EXTKEY'] = $extensionKey;
125 require_once $extTablesPath;
126 // We do not need to save restore the value of $GLOBALS['_EXTKEY']
127 // because it is not defined to anything real outside of
128 // ext_tables.php or ext_localconf.php scope.
129 unset($GLOBALS['_EXTKEY']);
130 }
131 }
132
133 /**
134 * Creating a single static cached instance of TSFE to use with this class.
135 *
136 * @return TypoScriptFrontendController
137 */
138 private static function getTSFE(): TypoScriptFrontendController
139 {
140 $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
141 $tsfe = $runtimeCache->get('eidUtilityTsfe') ?: null;
142 if ($tsfe === null) {
143 $tsfe = GeneralUtility::makeInstance(TypoScriptFrontendController::class, null, 0, 0);
144 $runtimeCache->set('eidUtilityTsfe', $tsfe);
145 }
146 return $tsfe;
147 }
148 }