Environment¶
Since version 9.x the TYPO3 Core includes an environment class.
This class contains all environment-specific information, e.g. paths within the
filesystem. This implementation replaces previously used global variables and
constants like PATH_
.
The fully qualified class name is \TYPO3\
. The
class provides static methods to access the necessary information.
To simulate environments in testing scenarios, the initialize
-method can
be called to adjust the information.
Environment PHP API¶
Tip
A comprehensive list of methods can be found in the Class Reference.
getProjectPath()¶
The environment provides the path to the folder containing the composer.
.
For projects without Composer setup, this is equal to getPublicPath().
getPublicPath()¶
The environment provides the path to the public web folder with
index.
for the TYPO3 frontend. This was previously PATH_
.
For projects without Composer setup, this is equal to getProjectPath().
getVarPath()¶
The environment provides the path to the var
folder. This folder contains
data like logs, sessions, locks, and cache files.
For projects with Composer setup, the value is get
,
so it is outside of the web document root - not within get
.
Without Composer, the value is get
, so within
the web document root - a situation that is not optimal from a security point of view.
getConfigPath()¶
The environment provides the path to typo3conf
. This folder contains TYPO3
global configuration files and folders, e.g. Local
.
For projects with Composer setup, the value is get
,
so it is outside of the web document root - not within get
.
Without Composer, the value is get
, so within
the web document root - a situation that is not optimal from a security point of view.
getLabelsPath()¶
The environment provides the path to labels
, respective l10n
folder. This folder contains downloaded translation files.
For projects with Composer setup, the value is get
,
so it is outside of the web document root - not within get
.
Without Composer, the value is get
, so within
the web document root - a situation that is not optimal from a security point of view.
getCurrentScript()¶
Returns the path and filename to the current PHP script.
getContext()¶
Returns the current Application context, usually defined via the TYPO3_
environment variable.
May be one of Production
, Testing
, or Development
with optional sub-contexts like Production/
.
Example, test for production context:
// use \TYPO3\CMS\Core\Core\Environment;
$applicationContext = Environment::getContext();
if ($applicationContext->isProduction()) {
// do something only when in production context
}