FE call or eiD include): index.php is located in the same directory * as the main project. The document root is identical to the directory the script is located at. * - The install tool, located under typo3/install.php. * - A Backend script: This is the case for the typo3/index.php dispatcher and other entry scripts like 'typo3/sysext/core/bin/typo3' * or 'typo3/index.php' that are located inside typo3/ directly. * * @param string $scriptPath Calculated path to the entry script * @param int $entryPointLevel Number of subdirectories where the entry script is located under the document root * @return string Absolute path to document root of installation */ protected static function getRootPathFromScriptPath($scriptPath, $entryPointLevel) { $entryScriptDirectory = PathUtility::dirnameDuringBootstrap($scriptPath); if ($entryPointLevel > 0) { list($rootPath) = GeneralUtility::revExplode('/', $entryScriptDirectory, $entryPointLevel + 1); } else { $rootPath = $entryScriptDirectory; } return $rootPath; } /** * Send http headers, echo out a text message and exit with error code * * @param string $message */ protected static function exitWithMessage($message) { $headers = [ \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_500, 'Content-Type: text/plain' ]; if (!headers_sent()) { foreach ($headers as $header) { header($header); } } echo $message . LF; exit(1); } /** * Check if the given function is disabled in the system * * @param string $function * @return bool */ public static function isFunctionDisabled($function) { if (static::$disabledFunctions === null) { static::$disabledFunctions = GeneralUtility::trimExplode(',', ini_get('disable_functions')); } if (!empty(static::$disabledFunctions)) { return in_array($function, static::$disabledFunctions, true); } return false; } /** * @return bool */ protected static function usesComposerClassLoading(): bool { return defined('TYPO3_COMPOSER_MODE') && TYPO3_COMPOSER_MODE; } /** * Define TYPO3_REQUESTTYPE* constants that can be used for developers to see if any context has been hit * also see setRequestType(). Is done at the very beginning so these parameters are always available. */ protected static function defineTypo3RequestTypes() { // Check one of the constants and return early if already defined, // needed if multiple requests are handled in one process, for instance in functional testing. if (defined('TYPO3_REQUESTTYPE_FE')) { return; } define('TYPO3_REQUESTTYPE_FE', self::REQUESTTYPE_FE); define('TYPO3_REQUESTTYPE_BE', self::REQUESTTYPE_BE); define('TYPO3_REQUESTTYPE_CLI', self::REQUESTTYPE_CLI); define('TYPO3_REQUESTTYPE_AJAX', self::REQUESTTYPE_AJAX); define('TYPO3_REQUESTTYPE_INSTALL', self::REQUESTTYPE_INSTALL); } /** * Defines the TYPO3_REQUESTTYPE constant so the environment knows which context the request is running. * * @param int $requestType */ protected static function setRequestType(int $requestType) { // Return early if already defined, // needed if multiple requests are handled in one process, for instance in functional testing. if (defined('TYPO3_REQUESTTYPE')) { return; } define('TYPO3_REQUESTTYPE', $requestType); } /** * Define constants and variables * * @param string */ protected static function defineLegacyConstants(string $mode) { // Return early if already defined, // needed if multiple requests are handled in one process, for instance in functional testing. if (defined('TYPO3_MODE')) { return; } define('TYPO3_MODE', $mode); } /** * Checks if request type is cli. * Falls back to check PHP_SAPI in case request type is not provided * * @param int|null $requestType * @return bool */ protected static function isCliRequestType(?int $requestType): bool { if ($requestType === null) { $requestType = PHP_SAPI === 'cli' ? self::REQUESTTYPE_CLI : self::REQUESTTYPE_FE; } return ($requestType & self::REQUESTTYPE_CLI) === self::REQUESTTYPE_CLI; } }