Environment
This class is initialized once in the SystemEnvironmentBuilder, and can then be used throughout the application to access common variables related to path-resolving and OS-/PHP-application specific information.
It's main design goal is to remove any access to constants within TYPO3 code and to provide a static, for TYPO3 core and extensions non-changeable information.
This class does not contain any HTTP related information, as this is handled in NormalizedParams functionality.
All path-related methods do return the realpath to the paths without (!) the trailing slash.
This class only defines what is configured through the environment, does not do any checks if paths exist etc. This should be part of the application or the SystemEnvironmentBuilder.
In your application, use it like this:
Instead of writing "TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI" call "Environment::isCli()"
Table of Contents
Properties
- $cli : bool
 - $composerMode : bool
 - $composerRootPath : string
 - $configPath : string
 - $context : ApplicationContext
 - $currentScript : string
 - $os : string
 - $projectPath : string
 - $publicPath : string
 - $supportedCgiServerApis : array<string|int, mixed>
 - A list of supported CGI server APIs
 - $varPath : string
 
Methods
- getBackendPath() : string
 - Previously known as PATH_typo3 Please note that this might be gone at some point
 - getComposerRootPath() : string
 - In most cases in composer-mode setups this is the same as project path.
 - getConfigPath() : string
 - The folder where all global (= installation-wide) configuration like - LocalConfiguration.php, - AdditionalConfiguration.php, and - PackageStates.php is put.
 - getContext() : ApplicationContext
 - Delivers the ApplicationContext object, usually defined in TYPO3_CONTEXT environment variables.
 - getCurrentScript() : string
 - The path + filename to the current PHP script.
 - getExtensionsPath() : string
 - Please note that this might be gone at some point
 - getFrameworkBasePath() : string
 - Previously known as PATH_typo3 . 'sysext/' Please note that this might be gone at some point
 - getLabelsPath() : string
 - Previously found under typo3conf/l10n/ Please note that this might be gone at some point
 - getLegacyConfigPath() : string
 - Previously known as PATH_typo3conf Please note that this might be gone at some point
 - getProjectPath() : string
 - The root path to the project. For installations set up via composer, this is the path where your composer.json file is stored. For non-composer-setups, this is (due to legacy reasons) the public web folder where the TYPO3 installation has been unzipped (something like htdocs/ or public/ on your webfolder).
 - getPublicPath() : string
 - The public web folder where index.php (= the frontend application) is put, without trailing slash.
 - getVarPath() : string
 - The folder where variable data like logs, sessions, locks, and cache files can be stored.
 - initialize() : mixed
 - Sets up the Environment. Please note that this is not public API and only used within the very early Set up of TYPO3, or to be used within tests. If you ever call this method in your extension, you're probably doing something wrong. Never call this method! Never rely on it!
 - isCli() : bool
 - Whether the current PHP request is handled by a CLI SAPI module or not.
 - isComposerMode() : bool
 - Informs whether TYPO3 has been installed via composer or not. Typically this is useful inside the Maintenance Modules, or the Extension Manager.
 - isRunningOnCgiServer() : bool
 - Returns true if the server is running on a list of supported CGI server APIs.
 - isUnix() : bool
 - Whether this TYPO3 installation runs on unix (= non-windows machines)
 - isWindows() : bool
 - Whether this TYPO3 installation runs on windows
 - toArray() : array<string|int, mixed>
 - Returns the currently configured Environment information as array.
 - usesCgiFixPathInfo() : bool
 
Properties
$cli
        protected
        static    bool
    $cli
    
    
    
    
    
    
$composerMode
        protected
        static    bool
    $composerMode
    
    
    
    
    
    
$composerRootPath
        protected
        static    string
    $composerRootPath
    
    
    
    
    
    
$configPath
        protected
        static    string
    $configPath
    
    
    
    
    
    
$context
        protected
        static    ApplicationContext
    $context
    
    
    
    
    
    
$currentScript
        protected
        static    string
    $currentScript
    
    
    
    
    
    
$os
        protected
        static    string
    $os
    
    
    
    
    
    
$projectPath
        protected
        static    string
    $projectPath
    
    
    
    
    
    
$publicPath
        protected
        static    string
    $publicPath
    
    
    
    
    
    
$supportedCgiServerApis
A list of supported CGI server APIs
        protected
        static    array<string|int, mixed>
    $supportedCgiServerApis
     = ['fpm-fcgi', 'cgi', 'isapi', 'cgi-fcgi', 'srv']
    
    
    
    
    
$varPath
        protected
        static    string
    $varPath
    
    
    
    
    
    
Methods
getBackendPath()
Previously known as PATH_typo3 Please note that this might be gone at some point
    public
            static        getBackendPath() : string
    Return values
stringgetComposerRootPath()
In most cases in composer-mode setups this is the same as project path.
    public
            static        getComposerRootPath() : string
    However since the project path is configurable, the paths may differ. In future versions this configurability will go away and this method will be removed. This path is only required for some internal path handling regarding package paths until then.
Return values
string —The absolute path to the composer root directory without the trailing slash
getConfigPath()
The folder where all global (= installation-wide) configuration like - LocalConfiguration.php, - AdditionalConfiguration.php, and - PackageStates.php is put.
    public
            static        getConfigPath() : string
    This folder usually has to be writable for TYPO3 in order to work.
When project path = public path, then this folder is usually typo3conf/, otherwise it's set to $project_path/config.
Return values
stringgetContext()
Delivers the ApplicationContext object, usually defined in TYPO3_CONTEXT environment variables.
    public
            static        getContext() : ApplicationContext
    This is something like "Production", "Testing", or "Development" or any additional information "Production/Staging".
Return values
ApplicationContextgetCurrentScript()
The path + filename to the current PHP script.
    public
            static        getCurrentScript() : string
    Return values
stringgetExtensionsPath()
Please note that this might be gone at some point
    public
            static        getExtensionsPath() : string
    Return values
stringgetFrameworkBasePath()
Previously known as PATH_typo3 . 'sysext/' Please note that this might be gone at some point
    public
            static        getFrameworkBasePath() : string
    Return values
stringgetLabelsPath()
Previously found under typo3conf/l10n/ Please note that this might be gone at some point
    public
            static        getLabelsPath() : string
    Return values
stringgetLegacyConfigPath()
Previously known as PATH_typo3conf Please note that this might be gone at some point
    public
            static        getLegacyConfigPath() : string
    Return values
stringgetProjectPath()
The root path to the project. For installations set up via composer, this is the path where your composer.json file is stored. For non-composer-setups, this is (due to legacy reasons) the public web folder where the TYPO3 installation has been unzipped (something like htdocs/ or public/ on your webfolder).
    public
            static        getProjectPath() : string
    However, non-composer-mode installations define an environment variable called "TYPO3_PATH_APP" to define a different folder (usually a parent folder) to allow TYPO3 to access and store data outside of the public web folder.
Return values
string —The absolute path to the project without the trailing slash
getPublicPath()
The public web folder where index.php (= the frontend application) is put, without trailing slash.
    public
            static        getPublicPath() : string
    For non-composer installations, the project path = the public path.
Return values
stringgetVarPath()
The folder where variable data like logs, sessions, locks, and cache files can be stored.
    public
            static        getVarPath() : string
    When project path = public path, then this folder is usually typo3temp/var/, otherwise it's set to $project_path/var.
Return values
stringinitialize()
Sets up the Environment. Please note that this is not public API and only used within the very early Set up of TYPO3, or to be used within tests. If you ever call this method in your extension, you're probably doing something wrong. Never call this method! Never rely on it!
    public
            static        initialize(ApplicationContext $context, bool $cli, bool $composerMode, string $projectPath, string $publicPath, string $varPath, string $configPath, string $currentScript, string $os) : mixed
    Parameters
- $context : ApplicationContext
 - $cli : bool
 - $composerMode : bool
 - $projectPath : string
 - $publicPath : string
 - $varPath : string
 - $configPath : string
 - $currentScript : string
 - $os : string
 
isCli()
Whether the current PHP request is handled by a CLI SAPI module or not.
    public
            static        isCli() : bool
    Return values
boolisComposerMode()
Informs whether TYPO3 has been installed via composer or not. Typically this is useful inside the Maintenance Modules, or the Extension Manager.
    public
            static        isComposerMode() : bool
    Return values
boolisRunningOnCgiServer()
Returns true if the server is running on a list of supported CGI server APIs.
    public
            static        isRunningOnCgiServer() : bool
    Return values
boolisUnix()
Whether this TYPO3 installation runs on unix (= non-windows machines)
    public
            static        isUnix() : bool
    Return values
boolisWindows()
Whether this TYPO3 installation runs on windows
    public
            static        isWindows() : bool
    Return values
booltoArray()
Returns the currently configured Environment information as array.
    public
            static        toArray() : array<string|int, mixed>
    Return values
array<string|int, mixed>usesCgiFixPathInfo()
    public
            static        usesCgiFixPathInfo() : bool