[TASK] Remove superfluous parenthesis in sysext core
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Core / Bootstrap.php
1 <?php
2 namespace TYPO3\CMS\Core\Core;
3
4 require 'SystemEnvironmentBuilder.php';
5
6 /**
7 * This class encapsulates bootstrap related methods.
8 * It is required directly as the very first thing in entry scripts and
9 * used to define all base things like constants and pathes and so on.
10 *
11 * Most methods in this class have dependencies to each other. They can
12 * not be called in arbitrary order. The methods are ordered top down, so
13 * a method at the beginning has lower dependencies than a method further
14 * down. Do not fiddle with the load order in own scripts except you know
15 * exactly what you are doing!
16 *
17 * @author Christian Kuhn <lolli@schwarzbu.ch>
18 * @package TYPO3
19 * @subpackage core
20 */
21 class Bootstrap {
22
23 /**
24 * @var \TYPO3\CMS\Core\Core\Bootstrap
25 */
26 static protected $instance = NULL;
27
28 /**
29 * Unique Request ID
30 *
31 * @var string
32 */
33 protected $requestId;
34
35 /**
36 * Disable direct creation of this object.
37 */
38 protected function __construct() {
39 $this->requestId = uniqid();
40 }
41
42 /**
43 * Disable direct cloning of this object.
44 */
45 protected function __clone() {
46
47 }
48
49 /**
50 * Return 'this' as singleton
51 *
52 * @return \TYPO3\CMS\Core\Core\Bootstrap
53 */
54 static public function getInstance() {
55 if (is_null(self::$instance)) {
56 self::$instance = new \TYPO3\CMS\Core\Core\Bootstrap();
57 }
58 return self::$instance;
59 }
60
61 /**
62 * Gets the request's unique ID
63 *
64 * @return string Unique request ID
65 */
66 public function getRequestId() {
67 return $this->requestId;
68 }
69
70 /**
71 * Prevent any unwanted output that may corrupt AJAX/compression.
72 * This does not interfere with "die()" or "echo"+"exit()" messages!
73 *
74 * @return \TYPO3\CMS\Core\Core\Bootstrap
75 */
76 public function startOutputBuffering() {
77 ob_start();
78 return $this;
79 }
80
81 /**
82 * Run the base setup that checks server environment,
83 * determines pathes, populates base files and sets common configuration.
84 *
85 * Script execution will be aborted if something fails here.
86 *
87 * @param string $relativePathPart Relative path of the entry script back to document root
88 * @return \TYPO3\CMS\Core\Core\Bootstrap
89 */
90 public function baseSetup($relativePathPart = '') {
91 \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run($relativePathPart);
92 return $this;
93 }
94
95 /**
96 * Throws an exception if no browser could be identified
97 *
98 * @return \TYPO3\CMS\Core\Core\Bootstrap
99 * @throws \RuntimeException
100 */
101 public function checkValidBrowserOrDie() {
102 // Checks for proper browser
103 if (empty($GLOBALS['CLIENT']['BROWSER'])) {
104 throw new \RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
105 }
106 return $this;
107 }
108
109 /**
110 * Register default ExtDirect components
111 *
112 * @return \TYPO3\CMS\Core\Core\Bootstrap
113 */
114 public function registerExtDirectComponents() {
115 if (TYPO3_MODE === 'BE') {
116 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.Components.PageTree.DataProvider', PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeDataProvide', 'web', 'user,group');
117 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.Components.PageTree.Commands', PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeCommands', 'web', 'user,group');
118 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.Components.PageTree.ContextMenuDataProvider', PATH_t3lib . 'contextmenu/pagetree/extdirect/class.t3lib_contextmenu_pagetree_extdirect_contextmenu.php:TYPO3\\CMS\\Backend\\ContextMenu\\Pagetree\\Extdirect\\ContextMenuConfiguration', 'web', 'user,group');
119 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.LiveSearchActions.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_backendlivesearch.php:extDirect_DataProvider_BackendLiveSearch', 'web_list', 'user,group');
120 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.BackendUserSettings.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php:TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
121 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.CSH.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_contexthelp.php:TYPO3\\CMS\\ContextHelp\\ExtDirect\\ContextHelpDataProvider');
122 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.ExtDirectStateProvider.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_state.php:TYPO3\\CMS\\Backend\\InterfaceState\\ExtDirect\\DataProvider');
123 }
124 return $this;
125 }
126
127 /**
128 * Populate the local configuration.
129 * Merge default TYPO3_CONF_VARS with content of typo3conf/LocalConfiguration.php,
130 * execute typo3conf/AdditionalConfiguration.php, define database related constants.
131 *
132 * @return \TYPO3\CMS\Core\Core\Bootstrap
133 */
134 public function populateLocalConfiguration() {
135 if (@is_file((PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCAL_CONFIGURATION_FILE))) {
136 $localConfiguration = \TYPO3\CMS\Core\Configuration\ConfigurationManager::getLocalConfiguration();
137 if (is_array($localConfiguration)) {
138 $GLOBALS['TYPO3_CONF_VARS'] = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($GLOBALS['TYPO3_CONF_VARS'], $localConfiguration);
139 } else {
140 die('LocalConfiguration invalid.');
141 }
142 if (@is_file((PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::ADDITIONAL_CONFIGURATION_FILE))) {
143 require PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::ADDITIONAL_CONFIGURATION_FILE;
144 }
145 define('TYPO3_db', $GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
146 define('TYPO3_db_username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
147 define('TYPO3_db_password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
148 define('TYPO3_db_host', $GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
149 define('TYPO3_extTableDef_script', $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']);
150 unset($GLOBALS['TYPO3_CONF_VARS']['DB']);
151 } elseif (@is_file((PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCALCONF_FILE))) {
152 // Legacy localconf.php handling
153 // @deprecated: Can be removed if old localconf.php is not supported anymore
154 global $TYPO3_CONF_VARS, $typo_db, $typo_db_username, $typo_db_password, $typo_db_host, $typo_db_extTableDef_script;
155 require PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCALCONF_FILE;
156 // If the localconf.php was not upgraded to LocalConfiguration.php, the default extListArray
157 // from t3lib/stddb/DefaultConfiguration.php is still set. In this case we just unset
158 // this key here, so t3lib_extMgm::getLoadedExtensionListArray() falls back to use extList string
159 // @deprecated: This case can be removed later if localconf.php is not supported anymore
160 unset($TYPO3_CONF_VARS['EXT']['extListArray']);
161 define('TYPO3_db', $typo_db);
162 define('TYPO3_db_username', $typo_db_username);
163 define('TYPO3_db_password', $typo_db_password);
164 define('TYPO3_db_host', $typo_db_host);
165 define('TYPO3_extTableDef_script', $typo_db_extTableDef_script);
166 unset($GLOBALS['typo_db']);
167 unset($GLOBALS['typo_db_username']);
168 unset($GLOBALS['typo_db_password']);
169 unset($GLOBALS['typo_db_host']);
170 unset($GLOBALS['typo_db_extTableDef_script']);
171 } else {
172 die(\TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCALCONF_FILE . ' not found!');
173 }
174 define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
175 return $this;
176 }
177
178 /**
179 * Redirect to install tool if database host and database are not defined
180 *
181 * @return \TYPO3\CMS\Core\Core\Bootstrap
182 */
183 public function redirectToInstallToolIfDatabaseCredentialsAreMissing() {
184 if (!TYPO3_db_host && !TYPO3_db) {
185 \TYPO3\CMS\Core\Utility\HttpUtility::redirect('install/index.php?mode=123&step=1&password=joh316');
186 }
187 return $this;
188 }
189
190 /**
191 * Initialize caching framework
192 *
193 * @return \TYPO3\CMS\Core\Core\Bootstrap
194 */
195 public function initializeCachingFramework() {
196 \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework();
197 return $this;
198 }
199
200 /**
201 * Register autoloader
202 *
203 * @return \TYPO3\CMS\Core\Core\Bootstrap
204 */
205 public function registerAutoloader() {
206 \TYPO3\CMS\Core\Autoloader::registerAutoloader();
207 return $this;
208 }
209
210 /**
211 * Checking for UTF-8 in the settings since TYPO3 4.5
212 *
213 * Since TYPO3 4.5, everything other than UTF-8 is deprecated.
214 *
215 * [BE][forceCharset] is set to the charset that TYPO3 is using
216 * [SYS][setDBinit] is used to set the DB connection
217 * and both settings need to be adjusted for UTF-8 in order to work properly
218 *
219 * @return \TYPO3\CMS\Core\Core\Bootstrap
220 */
221 public function checkUtf8DatabaseSettingsOrDie() {
222 // Check if [BE][forceCharset] has been set in localconf.php
223 if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'])) {
224 // die() unless we're already on UTF-8
225 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] != 'utf-8' && $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] && TYPO3_enterInstallScript !== '1') {
226 die('This installation was just upgraded to a new TYPO3 version. Since TYPO3 4.7, utf-8 is always enforced.<br />' . 'The configuration option $GLOBALS[\'TYPO3_CONF_VARS\'][BE][forceCharset] was marked as deprecated in TYPO3 4.5 and is now ignored.<br />' . 'You have configured the value to something different, which is not supported anymore.<br />' . 'Please proceed to the Update Wizard in the TYPO3 Install Tool to update your configuration.');
227 } else {
228 unset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
229 }
230 }
231 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) && $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] !== '-1' && preg_match('/SET NAMES utf8/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) === FALSE && TYPO3_enterInstallScript !== '1') {
232 // Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
233 die('This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10) . $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] . chr(10) . chr(10) . 'It looks like UTF-8 is not used for this connection.' . chr(10) . chr(10) . 'Everything other than UTF-8 is unsupported since TYPO3 4.7.' . chr(10) . 'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.');
234 } else {
235 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] = 'SET NAMES utf8;';
236 }
237 return $this;
238 }
239
240 /**
241 * Parse old curl options and set new http ones instead
242 *
243 * @TODO : This code segment must still be finished
244 * @return \TYPO3\CMS\Core\Core\Bootstrap
245 */
246 public function transferDeprecatedCurlSettings() {
247 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
248 $proxyParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
249 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
250 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
251 }
252 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
253 $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
254 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
255 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
256 }
257 return $this;
258 }
259
260 /**
261 * Set cacheHash options
262 *
263 * @return \TYPO3\CMS\Core\Core\Bootstrap
264 */
265 public function setCacheHashOptions() {
266 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
267 'cachedParametersWhiteList' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
268 'excludedParameters' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
269 'requireCacheHashPresenceParameters' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE)
270 );
271 if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
272 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
273 } else {
274 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
275 }
276 return $this;
277 }
278
279 /**
280 * $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] must be either
281 * 'digest' or 'basic' with fallback to 'basic'
282 *
283 * @return \TYPO3\CMS\Core\Core\Bootstrap
284 */
285 public function enforceCorrectProxyAuthScheme() {
286 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] === 'digest' ?: ($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'basic');
287 return $this;
288 }
289
290 /**
291 * Set default timezone
292 *
293 * @return \TYPO3\CMS\Core\Core\Bootstrap
294 */
295 public function setDefaultTimezone() {
296 $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
297 if (empty($timeZone)) {
298 // Time zone from the server environment (TZ env or OS query)
299 $defaultTimeZone = @date_default_timezone_get();
300 if ($defaultTimeZone !== '') {
301 $timeZone = $defaultTimeZone;
302 } else {
303 $timeZone = 'UTC';
304 }
305 }
306 // Set default to avoid E_WARNINGs with PHP > 5.3
307 date_default_timezone_set($timeZone);
308 return $this;
309 }
310
311 /**
312 * Initialize the locales handled by TYPO3
313 *
314 * @return \TYPO3\CMS\Core\Core\Bootstrap
315 */
316 public function initializeL10nLocales() {
317 \TYPO3\CMS\Core\Localization\Locales::initialize();
318 return $this;
319 }
320
321 /**
322 * Based on the configuration of the image processing some options are forced
323 * to simplify configuration settings and combinations
324 *
325 * @return \TYPO3\CMS\Core\Core\Bootstrap
326 */
327 public function configureImageProcessingOptions() {
328 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['image_processing']) {
329 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] = 0;
330 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = 0;
331 }
332 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
333 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'] = '';
334 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] = '';
335 $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,png';
336 $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] = 0;
337 }
338 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']) {
339 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 1;
340 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
341 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
342 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') {
343 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
344 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
345 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
346 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
347 }
348 }
349 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
350 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? 0 : 1;
351 }
352 return $this;
353 }
354
355 /**
356 * Convert type of "pageNotFound_handling" setting in case it was written as a
357 * string (e.g. if edited in Install Tool)
358 *
359 * @TODO : Remove, if the Install Tool handles such data types correctly
360 * @return \TYPO3\CMS\Core\Core\Bootstrap
361 */
362 public function convertPageNotFoundHandlingToBoolean() {
363 if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
364 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
365 }
366 return $this;
367 }
368
369 /**
370 * Register xdebug(), debug(), debugBegin() and debugEnd() as global functions
371 *
372 * Note: Yes, this is possible in php! xdebug() is then a global function, even
373 * if registerGlobalDebugFunctions() is encapsulated in class scope.
374 *
375 * @return \TYPO3\CMS\Core\Core\Bootstrap
376 */
377 public function registerGlobalDebugFunctions() {
378 require_once('GlobalDebugFunctions.php');
379 return $this;
380 }
381
382 /**
383 * Mail sending via Swift Mailer
384 *
385 * @return \TYPO3\CMS\Core\Core\Bootstrap
386 */
387 public function registerSwiftMailer() {
388 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][] = 'TYPO3\\CMS\\Core\\Mail\\SwiftMailerAdapter';
389 return $this;
390 }
391
392 /**
393 * Configure and set up exception and error handling
394 *
395 * @return \TYPO3\CMS\Core\Core\Bootstrap
396 */
397 public function configureExceptionHandling() {
398 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
399 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
400 // Turn error logging on/off.
401 if (($displayErrors = intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'])) != '-1') {
402 // Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
403 if ($displayErrors == 2) {
404 if (\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
405 $displayErrors = 1;
406 } else {
407 $displayErrors = 0;
408 }
409 }
410 if ($displayErrors == 0) {
411 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
412 }
413 if ($displayErrors == 1) {
414 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
415 define('TYPO3_ERRORHANDLER_MODE', 'debug');
416 }
417 @ini_set('display_errors', $displayErrors);
418 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
419 // With displayErrors = -1 (default), turn on debugging if devIPmask matches:
420 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
421 }
422 return $this;
423 }
424
425 /**
426 * Set PHP memory limit depending on value of
427 * $GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']
428 *
429 * @return \TYPO3\CMS\Core\Core\Bootstrap
430 */
431 public function setMemoryLimit() {
432 if (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) > 16) {
433 @ini_set('memory_limit', (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) . 'm'));
434 }
435 return $this;
436 }
437
438 /**
439 * Define TYPO3_REQUESTTYPE* constants
440 * so devs exactly know what type of request it is
441 *
442 * @return \TYPO3\CMS\Core\Core\Bootstrap
443 */
444 public function defineTypo3RequestTypes() {
445 define('TYPO3_REQUESTTYPE_FE', 1);
446 define('TYPO3_REQUESTTYPE_BE', 2);
447 define('TYPO3_REQUESTTYPE_CLI', 4);
448 define('TYPO3_REQUESTTYPE_AJAX', 8);
449 define('TYPO3_REQUESTTYPE_INSTALL', 16);
450 define('TYPO3_REQUESTTYPE', (TYPO3_MODE == 'FE' ? TYPO3_REQUESTTYPE_FE : 0) | (TYPO3_MODE == 'BE' ? TYPO3_REQUESTTYPE_BE : 0) | (defined('TYPO3_cliMode') && TYPO3_cliMode ? TYPO3_REQUESTTYPE_CLI : 0) | (defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript ? TYPO3_REQUESTTYPE_INSTALL : 0) | ($GLOBALS['TYPO3_AJAX'] ? TYPO3_REQUESTTYPE_AJAX : 0));
451 return $this;
452 }
453
454 /**
455 * Set up $GLOBALS['TYPO3_LOADED_EXT'] array with basic information
456 * about extensions.
457 *
458 * @param boolean $allowCaching
459 * @return \TYPO3\CMS\Core\Core\Bootstrap
460 */
461 public function populateTypo3LoadedExtGlobal($allowCaching = TRUE) {
462 $GLOBALS['TYPO3_LOADED_EXT'] = \TYPO3\CMS\Core\Extension\ExtensionManager::loadTypo3LoadedExtensionInformation($allowCaching);
463 return $this;
464 }
465
466 /**
467 * Load extension configuration files (ext_localconf.php)
468 *
469 * The ext_localconf.php files in extensions are meant to make changes
470 * to the global $TYPO3_CONF_VARS configuration array.
471 *
472 * @param boolean $allowCaching
473 * @return \TYPO3\CMS\Core\Core\Bootstrap
474 */
475 public function loadAdditionalConfigurationFromExtensions($allowCaching = TRUE) {
476 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtLocalconf($allowCaching);
477 return $this;
478 }
479
480 /**
481 * Write deprecation log if deprecated extCache setting was set in the instance.
482 *
483 * @return \TYPO3\CMS\Core\Core\Bootstrap
484 * @deprecated since 6.0, the check will be removed two version later.
485 */
486 public function deprecationLogForOldExtCacheSetting() {
487 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache']) && $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] !== -1) {
488 \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('Setting $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'extCache\'] is unused and can be removed from localconf.php');
489 }
490 return $this;
491 }
492
493 /**
494 * Initialize exception handling
495 *
496 * @return \TYPO3\CMS\Core\Core\Bootstrap
497 */
498 public function initializeExceptionHandling() {
499 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
500 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== '') {
501 // Register an error handler for the given errorHandlerErrors
502 $errorHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']);
503 // Set errors which will be converted in an exception
504 $errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
505 }
506 // Instantiate the exception handler once to make sure object is registered
507 // @TODO: Figure out if this is really needed
508 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']);
509 }
510 return $this;
511 }
512
513 /**
514 * Load some additional classes that are encapsulated in extensions
515 *
516 * @return \TYPO3\CMS\Core\Core\Bootstrap
517 */
518 public function requireAdditionalExtensionFiles() {
519 require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('lang') . 'lang.php';
520 return $this;
521 }
522
523 /**
524 * Extensions may register new caches, so we set the
525 * global cache array to the manager again at this point
526 *
527 * @return \TYPO3\CMS\Core\Core\Bootstrap
528 */
529 public function setFinalCachingFrameworkCacheConfiguration() {
530 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
531 return $this;
532 }
533
534 /**
535 * Define logging and exception constants
536 *
537 * @return \TYPO3\CMS\Core\Core\Bootstrap
538 */
539 public function defineLoggingAndExceptionConstants() {
540 define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
541 define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
542 define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
543 return $this;
544 }
545
546 /**
547 * Unsetting reserved global variables:
548 * Those which are/can be set in "stddb/tables.php" files:
549 *
550 * @return \TYPO3\CMS\Core\Core\Bootstrap
551 */
552 public function unsetReservedGlobalVariables() {
553 unset($GLOBALS['PAGES_TYPES']);
554 unset($GLOBALS['TCA']);
555 unset($GLOBALS['TBE_MODULES']);
556 unset($GLOBALS['TBE_STYLES']);
557 unset($GLOBALS['FILEICONS']);
558 // Those set in init.php:
559 unset($GLOBALS['WEBMOUNTS']);
560 unset($GLOBALS['FILEMOUNTS']);
561 unset($GLOBALS['BE_USER']);
562 // Those set otherwise:
563 unset($GLOBALS['TBE_MODULES_EXT']);
564 unset($GLOBALS['TCA_DESCR']);
565 unset($GLOBALS['LOCAL_LANG']);
566 unset($GLOBALS['TYPO3_AJAX']);
567 return $this;
568 }
569
570 /**
571 * Initialize t3lib_db in $GLOBALS and connect if requested
572 *
573 * @param boolean $connect Whether or not the db should be connected already
574 * @return \TYPO3\CMS\Core\Core\Bootstrap
575 */
576 public function initializeTypo3DbGlobal($connect = TRUE) {
577 /** @var TYPO3_DB t3lib_db */
578 $GLOBALS['TYPO3_DB'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
579 $GLOBALS['TYPO3_DB']->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
580 if ($connect) {
581 $this->establishDatabaseConnection();
582 }
583 return $this;
584 }
585
586 /**
587 * Check adminOnly configuration variable and redirects
588 * to an URL in file typo3conf/LOCK_BACKEND or exit the script
589 *
590 * @throws \RuntimeException
591 * @return \TYPO3\CMS\Core\Core\Bootstrap
592 */
593 public function checkLockedBackendAndRedirectOrDie() {
594 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
595 throw new \RuntimeException('TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly']) . '".', 1294586847);
596 }
597 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
598 if (TYPO3_PROCEED_IF_NO_USER === 2) {
599
600 } else {
601 $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
602 if ($fileContent) {
603 header('Location: ' . $fileContent);
604 } else {
605 throw new \RuntimeException('TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.', 1294586848);
606 }
607 die;
608 }
609 }
610 return $this;
611 }
612
613 /**
614 * Compare client IP with IPmaskList and exit the script run
615 * if the client is not allowed to access the backend
616 *
617 * @return \TYPO3\CMS\Core\Core\Bootstrap
618 */
619 public function checkBackendIpOrDie() {
620 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
621 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
622 // Send Not Found header - if the webserver can make use of it
623 header('Status: 404 Not Found');
624 // Just point us away from here...
625 header('Location: http://');
626 // ... and exit good!
627 die;
628 }
629 }
630 return $this;
631 }
632
633 /**
634 * Check lockSSL configuration variable and redirect
635 * to https version of the backend if needed
636 *
637 * @return \TYPO3\CMS\Core\Core\Bootstrap
638 */
639 public function checkSslBackendAndRedirectIfNeeded() {
640 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
641 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
642 $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
643 } else {
644 $sslPortSuffix = '';
645 }
646 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
647 $requestStr = substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
648 if ($requestStr === 'index.php' && !\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
649 list(, $url) = explode('://', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 2);
650 list($server, $address) = explode('/', $url, 2);
651 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
652 die;
653 }
654 } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
655 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) === 2) {
656 list(, $url) = explode('://', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
657 list($server, $address) = explode('/', $url, 2);
658 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
659 } else {
660 // Send Not Found header - if the webserver can make use of it...
661 header('Status: 404 Not Found');
662 // Just point us away from here...
663 header('Location: http://');
664 }
665 // ... and exit good!
666 die;
667 }
668 }
669 return $this;
670 }
671
672 /**
673 * Establish connection to the database
674 *
675 * @return \TYPO3\CMS\Core\Core\Bootstrap
676 */
677 public function establishDatabaseConnection() {
678 $GLOBALS['TYPO3_DB']->connectDB();
679 return $this;
680 }
681
682 /**
683 * Load ext_tables and friends.
684 *
685 * This will mainly set up $TCA and several other global arrays
686 * through API's like extMgm.
687 * Executes ext_tables.php files of loaded extensions or the
688 * according cache file if exists.
689 *
690 * Note: For backwards compatibility some global variables are
691 * explicitly set as global to be used without $GLOBALS[] in
692 * ext_tables.php. It is discouraged to access variables like
693 * $TBE_MODULES directly in ext_tables.php, but we can not prohibit
694 * this without heavily breaking backwards compatibility.
695 *
696 * @TODO : We could write a scheduler / reports module or an update checker
697 * @TODO : It should be defined, which global arrays are ok to be manipulated
698 * @param boolean $allowCaching True, if reading compiled ext_tables file from cache is allowed
699 * @return \TYPO3\CMS\Core\Core\Bootstrap
700 */
701 public function loadExtensionTables($allowCaching = TRUE) {
702 // It is discouraged to use those global variables directly, but we
703 // can not prohibit this without breaking backwards compatibility
704 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
705 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
706 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
707 global $_EXTKEY;
708 // Include standard tables.php file
709 require PATH_t3lib . 'stddb/tables.php';
710 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtTables($allowCaching);
711 // Load additional ext tables script if registered
712 if (TYPO3_extTableDef_script) {
713 include PATH_typo3conf . TYPO3_extTableDef_script;
714 }
715 // Run post hook for additional manipulation
716 $this->runExtTablesPostProcessingHooks();
717 return $this;
718 }
719
720 /**
721 * Check for registered ext tables hooks and run them
722 *
723 * @throws \UnexpectedValueException
724 * @return \TYPO3\CMS\Core\Core\Bootstrap
725 */
726 protected function runExtTablesPostProcessingHooks() {
727 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
728 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
729 /** @var $hookObject \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface */
730 $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classReference);
731 if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
732 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface', 1320585902);
733 }
734 $hookObject->processData();
735 }
736 }
737 return $this;
738 }
739
740 /**
741 * Initialize sprite manager
742 *
743 * @return \TYPO3\CMS\Core\Core\Bootstrap
744 */
745 public function initializeSpriteManager() {
746 \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
747 return $this;
748 }
749
750 /**
751 * Initialize backend user object in globals
752 *
753 * @return \TYPO3\CMS\Core\Core\Bootstrap
754 */
755 public function initializeBackendUser() {
756 /** @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
757 $backendUser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
758 $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
759 $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
760 $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
761 $backendUser->OS = TYPO3_OS;
762 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
763 $backendUser->dontSetCookie = TRUE;
764 }
765 $backendUser->start();
766 $backendUser->checkCLIuser();
767 $backendUser->backendCheckLogin();
768 $GLOBALS['BE_USER'] = $backendUser;
769 return $this;
770 }
771
772 /**
773 * Initialize backend user mount points
774 *
775 * @return \TYPO3\CMS\Core\Core\Bootstrap
776 */
777 public function initializeBackendUserMounts() {
778 // Includes deleted mount pages as well! @TODO: Figure out why ...
779 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
780 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->returnFilemounts();
781 return $this;
782 }
783
784 /**
785 * Initialize language object
786 *
787 * @return \TYPO3\CMS\Core\Core\Bootstrap
788 */
789 public function initializeLanguageObject() {
790 /** @var $GLOBALS['LANG'] \TYPO3\CMS\Lang\LanguageService */
791 $GLOBALS['LANG'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Lang\LanguageService');
792 $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
793 return $this;
794 }
795
796 /**
797 * Throw away all output that may have happened during bootstrapping by weird extensions
798 *
799 * @return \TYPO3\CMS\Core\Core\Bootstrap
800 */
801 public function endOutputBufferingAndCleanPreviousOutput() {
802 ob_clean();
803 return $this;
804 }
805
806 /**
807 * Initialize output compression if configured
808 *
809 * @return \TYPO3\CMS\Core\Core\Bootstrap
810 */
811 public function initializeOutputCompression() {
812 if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
813 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
814 @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
815 }
816 ob_start('ob_gzhandler');
817 }
818 return $this;
819 }
820
821 /**
822 * Initialize module menu object
823 *
824 * @return \TYPO3\CMS\Core\Core\Bootstrap
825 */
826 public function initializeModuleMenuObject() {
827 /** @var $moduleMenuUtility Typo3_BackendModule_Utility */
828 $moduleMenuUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleController');
829 $moduleMenuUtility->createModuleMenu();
830 return $this;
831 }
832
833 /**
834 * Things that should be performed to shut down the framework.
835 * This method is called in all important scripts for a clean
836 * shut down of the system.
837 *
838 * @return \TYPO3\CMS\Core\Core\Bootstrap
839 */
840 public function shutdown() {
841 \TYPO3\CMS\Core\Autoloader::unregisterAutoloader();
842 return $this;
843 }
844
845 /**
846 * Provides an instance of "template" for backend-modules to
847 * work with.
848 *
849 * @return \TYPO3\CMS\Core\Core\Bootstrap
850 */
851 public function initializeBackendTemplate() {
852 $GLOBALS['TBE_TEMPLATE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
853 return $this;
854 }
855
856 }
857
858
859 ?>