SystemEnvironmentBuilder
Class to encapsulate base setup of bootstrap.
This class contains all code that must be executed by every entry script.
It sets up all basic paths, constants, global variables and checks the basic environment TYPO3 runs in.
This class does not use any TYPO3 instance specific configuration, it only sets up things based on the server environment and core code. Even with a missing system/settings.php this script will be successful.
The script aborts execution with an error message if some part fails or conditions are not met.
This script is internal code and subject to change.
Note that changes in this file must be carefully tested along with the typo3/testing-framework not only in Core CI, but also when used to test extensions or projects to ensure that things like link generation works as expected and returns leading slashes, important value calculation in NormalizedParams during frontend sub-requests determines correct values and similar.
Table of Contents
Constants
- REQUESTTYPE_AJAX = 8
- REQUESTTYPE_BE = 2
- REQUESTTYPE_CLI = 4
- REQUESTTYPE_FE = 1
- REQUESTTYPE_INSTALL = 16
Methods
- run() : mixed
- Run base setup.
- calculateRootPath() : string
- Absolute path to the "classic" site root of the TYPO3 application.
- calculateScriptPath() : string
- Calculate script path. This is the absolute path to the entry script.
- createApplicationContext() : ApplicationContext
- Some notes:
- defineBaseConstants() : mixed
- Define all simple constants that have no dependency to local configuration
- getDefinedPathRoot() : string
- getPathThisScript() : string
- Calculate script path.
- getPathThisScriptCli() : string
- Calculate path to entry script if in cli mode.
- getPathThisScriptNonCli() : string
- Return path to entry script if not in cli mode.
- getRootPathFromScriptPath() : string
- Calculate the document root part to the instance from $scriptPath.
- initializeEnvironment() : mixed
- Initialize the Environment class
- initializeGlobalTimeTrackingVariables() : mixed
- Initialize global time tracking variables.
- initializeGlobalVariables() : mixed
- Set up / initialize several globals variables
- isCliRequestType() : bool
- Checks if request type is cli.
- isRunningOnWindows() : bool
- Determine if the operating system TYPO3 is running on is windows.
- usesComposerClassLoading() : bool
Constants
REQUESTTYPE_AJAX
public
mixed
REQUESTTYPE_AJAX
= 8
REQUESTTYPE_BE
public
mixed
REQUESTTYPE_BE
= 2
REQUESTTYPE_CLI
public
mixed
REQUESTTYPE_CLI
= 4
REQUESTTYPE_FE
public
mixed
REQUESTTYPE_FE
= 1
REQUESTTYPE_INSTALL
public
mixed
REQUESTTYPE_INSTALL
= 16
Methods
run()
Run base setup.
public
static run([int $entryPointLevel = 0 ][, int $requestType = 0 ]) : mixed
This entry method is used in all scopes (FE, BE, Install Tool and CLI)
Parameters
- $entryPointLevel : int = 0
-
Number of subdirectories where the entry script is located under the document root
- $requestType : int = 0
This method should not be used by 3rd party code. It will change without further notice.
calculateRootPath()
Absolute path to the "classic" site root of the TYPO3 application.
protected
static calculateRootPath(int $entryPointLevel, int $requestType) : string
This semantically refers to the directory where executable server-side code, configuration and runtime files are located (e.g. typo3conf/ext, typo3/sysext, typo3temp/var). In practice this is always identical to the public web document root path which contains files that are served by the webserver directly (fileadmin/ and public resources).
This is not to be confused with the app-path that is used in composer-mode installations (by default). Resources in app-path are located outside the document root.
Parameters
- $entryPointLevel : int
-
Number of subdirectories where the entry script is located under the document root
- $requestType : int
Return values
string —Absolute path without trailing slash
calculateScriptPath()
Calculate script path. This is the absolute path to the entry script.
protected
static calculateScriptPath(int $entryPointLevel, int $requestType) : string
Can be something like '.../public/index.php' for web calls, or '.../bin/typo3' or similar for cli calls.
Parameters
- $entryPointLevel : int
-
Number of subdirectories where the entry script is located under the document root
- $requestType : int
Return values
string —Absolute path to entry script
createApplicationContext()
Some notes:
protected
static createApplicationContext() : ApplicationContext
HTTP_TYPO3_CONTEXT -> used with Apache suexec support REDIRECT_TYPO3_CONTEXT -> used under some circumstances when value is set in the webserver and proxying the values to FPM
Tags
Return values
ApplicationContextdefineBaseConstants()
Define all simple constants that have no dependency to local configuration
protected
static defineBaseConstants() : mixed
getDefinedPathRoot()
protected
static getDefinedPathRoot() : string
Return values
stringgetPathThisScript()
Calculate script path.
protected
static getPathThisScript(bool $isCli) : string
First step in path calculation: Goal is to find the absolute path of the entry script that was called without resolving any links. This is important since the TYPO3 entry points are often linked to a central core location, so we can not use the php magic FILE here, but resolve the called script path from given server environments.
This path is important to calculate the document root. The strategy is to find out the script name that was called in the first place and to subtract the local part from it to find the document root.
Parameters
- $isCli : bool
Return values
string —Absolute path to entry script
getPathThisScriptCli()
Calculate path to entry script if in cli mode.
protected
static getPathThisScriptCli() : string
First argument of a cli script is the path to the script that was called. If the script does not start with / (or A:\ for Windows), the path is not absolute yet, and the current working directory is added.
Return values
string —Absolute path to entry script
getPathThisScriptNonCli()
Return path to entry script if not in cli mode.
protected
static getPathThisScriptNonCli() : string
Return values
string —Absolute path to entry script
getRootPathFromScriptPath()
Calculate the document root part to the instance from $scriptPath.
protected
static getRootPathFromScriptPath(string $scriptPath, int $entryPointLevel) : string
This is based on the amount of subdirectories "under" root path where $scriptPath is located.
The following main scenarios for entry points exist by default in the TYPO3 core:
- Directly called documentRoot/index.php (-> 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.
- The CLI script 'typo3/sysext/core/bin/typo3' which is located inside typo3/ directly.
Parameters
- $scriptPath : string
-
Calculated path to the entry script
- $entryPointLevel : int
-
Number of subdirectories where the entry script is located under the document root
Return values
string —Absolute path to document root of installation without trailing slash
initializeEnvironment()
Initialize the Environment class
protected
static initializeEnvironment(int $requestType, string $scriptPath, string $sitePath) : mixed
Parameters
- $requestType : int
- $scriptPath : string
- $sitePath : string
initializeGlobalTimeTrackingVariables()
Initialize global time tracking variables.
protected
static initializeGlobalTimeTrackingVariables() : mixed
These are helpers to for example output script parsetime at the end of a script.
initializeGlobalVariables()
Set up / initialize several globals variables
protected
static initializeGlobalVariables() : mixed
isCliRequestType()
Checks if request type is cli.
protected
static isCliRequestType(int|null $requestType) : bool
Falls back to check PHP_SAPI in case request type is not provided
Parameters
- $requestType : int|null
Return values
boolisRunningOnWindows()
Determine if the operating system TYPO3 is running on is windows.
protected
static isRunningOnWindows() : bool
Return values
boolusesComposerClassLoading()
protected
static usesComposerClassLoading() : bool