[!!!][TASK] Remove deprecated connectDB from EidUtility
[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 /**
18 * Tools for scripts using the eID feature of index.php
19 * Included from index_ts.php
20 * Since scripts using the eID feature does not
21 * have a full FE environment initialized by default
22 * this class seeks to provide functions that can
23 * initialize parts of the FE environment as needed,
24 * eg. Frontend User session, Database connection etc.
25 *
26 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
27 * @author Dmitry Dulepov <dmitry@typo3.org>
28 */
29 class EidUtility {
30
31 /**
32 * Load and initialize Frontend User. Note, this process is slow because
33 * it creates a calls many objects. Call this method only if necessary!
34 *
35 * @return object Frontend User object (usually known as TSFE->fe_user)
36 */
37 static public function initFeUser() {
38 // Get TSFE instance. It knows how to initialize the user. We also
39 // need TCA because services may need extra tables!
40 self::initTCA();
41 /** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
42 $tsfe = self::getTSFE();
43 $tsfe->initFEuser();
44 // Return FE user object:
45 return $tsfe->fe_user;
46 }
47
48 /**
49 * Initializes $GLOBALS['LANG'] for use in eID scripts.
50 *
51 * @param string $language TYPO3 language code
52 * @return void
53 */
54 static public function initLanguage($language = 'default') {
55 if (!is_object($GLOBALS['LANG'])) {
56 $GLOBALS['LANG'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService');
57 $GLOBALS['LANG']->init($language);
58 }
59 }
60
61 /**
62 * Makes TCA available inside eID
63 *
64 * @return void
65 */
66 static public function initTCA() {
67 // Some badly made extensions attempt to manipulate TCA in a wrong way
68 // (inside ext_localconf.php). Therefore $GLOBALS['TCA'] may become an array
69 // but in fact it is not loaded. The check below ensure that
70 // TCA is still loaded if such bad extensions are installed
71 if (!is_array($GLOBALS['TCA']) || !isset($GLOBALS['TCA']['pages'])) {
72 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadCachedTca();
73 }
74 }
75
76 /**
77 * Makes TCA for the extension available inside eID. Use this function if
78 * you need not to include the whole $GLOBALS['TCA'].
79 *
80 * @param string $extensionKey Extension key
81 * @return void
82 */
83 static public function initExtensionTCA($extensionKey) {
84 $extTablesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey, 'ext_tables.php');
85 if (file_exists($extTablesPath)) {
86 $GLOBALS['_EXTKEY'] = $extensionKey;
87 require_once $extTablesPath;
88 // We do not need to save restore the value of $GLOBALS['_EXTKEY']
89 // because it is not defined to anything real outside of
90 // ext_tables.php or ext_localconf.php scope.
91 unset($GLOBALS['_EXTKEY']);
92 }
93 }
94
95 /**
96 * Creating a single static cached instance of TSFE to use with this class.
97 *
98 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController New instance of \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
99 */
100 static private function getTSFE() {
101 // Cached instance
102 static $tsfe = NULL;
103 if (is_null($tsfe)) {
104 $tsfe = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], 0, 0);
105 }
106 return $tsfe;
107 }
108
109 }