‪TYPO3CMS  ‪main
Environment.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 namespace ‪TYPO3\CMS\Core\Core;
19 
20 use Composer\InstalledVersions;
22 
41 {
46  protected static ‪$supportedCgiServerApis = [
47  'fpm-fcgi',
48  'cgi',
49  'isapi',
50  'cgi-fcgi',
51  'srv', // HHVM with fastcgi
52  ];
53 
57  protected static ‪$cli;
58 
62  protected static ‪$composerMode;
63 
67  protected static ‪$context;
68 
72  protected static ‪$projectPath;
73 
77  protected static ‪$composerRootPath;
78 
82  protected static ‪$publicPath;
83 
87  protected static ‪$currentScript;
88 
92  protected static ‪$os;
93 
97  protected static ‪$varPath;
98 
102  protected static ‪$configPath;
103 
111  public static function ‪initialize(
113  bool ‪$cli,
114  bool ‪$composerMode,
115  string ‪$projectPath,
116  string ‪$publicPath,
117  string ‪$varPath,
118  string ‪$configPath,
119  string ‪$currentScript,
120  string ‪$os
121  ) {
122  self::$cli = ‪$cli;
123  self::$composerMode = ‪$composerMode;
124  self::$context = ‪$context;
125  self::$projectPath = ‪$projectPath;
126  self::$composerRootPath = ‪$composerMode ? ‪PathUtility::getCanonicalPath(InstalledVersions::getRootPackage()['install_path']) : '';
127  self::$publicPath = ‪$publicPath;
128  self::$varPath = ‪$varPath;
129  self::$configPath = ‪$configPath;
130  self::$currentScript = ‪$currentScript;
131  self::$os = ‪$os;
132  }
133 
139  public static function ‪getContext(): ‪ApplicationContext
140  {
141  return ‪self::$context;
142  }
143 
148  public static function ‪isComposerMode(): bool
149  {
150  return ‪self::$composerMode;
151  }
152 
156  public static function ‪isCli(): bool
157  {
158  return ‪self::$cli;
159  }
160 
171  public static function ‪getProjectPath(): string
172  {
173  return ‪self::$projectPath;
174  }
175 
185  public static function ‪getComposerRootPath(): string
186  {
187  if (self::$composerMode === false) {
188  throw new \BadMethodCallException('Composer root path is only available in Composer mode', 1631700480);
189  }
190 
192  }
193 
198  public static function ‪getPublicPath(): string
199  {
200  return ‪self::$publicPath;
201  }
202 
208  public static function ‪getVarPath(): string
209  {
210  return ‪self::$varPath;
211  }
212 
223  public static function ‪getConfigPath(): string
224  {
225  return ‪self::$configPath;
226  }
227 
231  public static function ‪getCurrentScript(): string
232  {
234  }
235 
244  public static function ‪getLabelsPath(): string
245  {
246  if (self::$publicPath === self::$projectPath) {
247  return ‪self::getPublicPath() . '/typo3conf/l10n';
248  }
249  return ‪self::getVarPath() . '/labels';
250  }
251 
257  public static function ‪getBackendPath(): string
258  {
259  trigger_error('Environment::getBackendPath() will be removed in TYPO3 v13.0.', E_USER_DEPRECATED);
260  return ‪self::getPublicPath() . '/typo3';
261  }
262 
267  public static function ‪getFrameworkBasePath(): string
268  {
269  return ‪self::getPublicPath() . '/typo3/sysext';
270  }
271 
275  public static function ‪getExtensionsPath(): string
276  {
277  return ‪self::getPublicPath() . '/typo3conf/ext';
278  }
279 
290  public static function ‪getLegacyConfigPath(): string
291  {
292  return ‪self::getPublicPath() . '/typo3conf';
293  }
294 
298  public static function ‪isWindows(): bool
299  {
300  return self::$os === 'WINDOWS';
301  }
302 
306  public static function ‪isUnix(): bool
307  {
308  return self::$os === 'UNIX';
309  }
310 
314  public static function ‪isRunningOnCgiServer(): bool
315  {
316  return in_array(PHP_SAPI, self::$supportedCgiServerApis, true);
317  }
318 
319  public static function ‪usesCgiFixPathInfo(): bool
320  {
321  return !empty(ini_get('cgi.fix_pathinfo'));
322  }
323 
327  public static function ‪toArray(): array
328  {
329  return [
330  'context' => (string)self::getContext(),
331  'cli' => ‪self::isCli(),
332  'projectPath' => ‪self::getProjectPath(),
333  'publicPath' => ‪self::getPublicPath(),
334  'varPath' => ‪self::getVarPath(),
335  'configPath' => ‪self::getConfigPath(),
336  'currentScript' => ‪self::getCurrentScript(),
337  'os' => ‪self::isWindows() ? 'WINDOWS' : 'UNIX',
338  ];
339  }
340 }
‪TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath
‪static string getCanonicalPath(string $path)
Definition: PathUtility.php:364
‪TYPO3\CMS\Core\Core\Environment\isUnix
‪static isUnix()
Definition: Environment.php:295
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Core\Environment\$composerMode
‪static bool $composerMode
Definition: Environment.php:59
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:39
‪TYPO3\CMS\Core\Core\Environment\getComposerRootPath
‪static string getComposerRootPath()
Definition: Environment.php:174
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Core\Environment\$currentScript
‪static string $currentScript
Definition: Environment.php:79
‪TYPO3\CMS\Core\Core\Environment\getLabelsPath
‪static getLabelsPath()
Definition: Environment.php:233
‪TYPO3\CMS\Core\Core\Environment\getExtensionsPath
‪static getExtensionsPath()
Definition: Environment.php:264
‪TYPO3\CMS\Core\Core\Environment\getCurrentScript
‪static getCurrentScript()
Definition: Environment.php:220
‪TYPO3\CMS\Core\Core\Environment\$projectPath
‪static string $projectPath
Definition: Environment.php:67
‪TYPO3\CMS\Core\Core\Environment\toArray
‪static toArray()
Definition: Environment.php:316
‪TYPO3\CMS\Core\Core\Environment\$cli
‪static bool $cli
Definition: Environment.php:55
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Core\Environment\getBackendPath
‪static getBackendPath()
Definition: Environment.php:246
‪TYPO3\CMS\Core\Core\Environment\getLegacyConfigPath
‪static getLegacyConfigPath()
Definition: Environment.php:279
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static getConfigPath()
Definition: Environment.php:212
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:160
‪TYPO3\CMS\Core\Core\Environment\$os
‪static string $os
Definition: Environment.php:83
‪TYPO3\CMS\Core\Core\Environment\usesCgiFixPathInfo
‪static usesCgiFixPathInfo()
Definition: Environment.php:308
‪TYPO3\CMS\Core\Core\Environment\initialize
‪static initialize(ApplicationContext $context, bool $cli, bool $composerMode, string $projectPath, string $publicPath, string $varPath, string $configPath, string $currentScript, string $os)
Definition: Environment.php:100
‪TYPO3\CMS\Core\Core\Environment\$publicPath
‪static string $publicPath
Definition: Environment.php:75
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static isCli()
Definition: Environment.php:145
‪TYPO3\CMS\Core\Core\Environment\$varPath
‪static string $varPath
Definition: Environment.php:87
‪TYPO3\CMS\Core\Core\Environment\getFrameworkBasePath
‪static getFrameworkBasePath()
Definition: Environment.php:256
‪TYPO3\CMS\Core\Core\Environment\$composerRootPath
‪static string $composerRootPath
Definition: Environment.php:71
‪TYPO3\CMS\Core\Core\Environment\isRunningOnCgiServer
‪static isRunningOnCgiServer()
Definition: Environment.php:303
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Core
Definition: ApplicationContext.php:16
‪TYPO3\CMS\Core\Core\Environment\$context
‪static ApplicationContext $context
Definition: Environment.php:63
‪TYPO3\CMS\Core\Core\Environment\$supportedCgiServerApis
‪static array $supportedCgiServerApis
Definition: Environment.php:45
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static getContext()
Definition: Environment.php:128
‪TYPO3\CMS\Core\Core\Environment\$configPath
‪static string $configPath
Definition: Environment.php:91
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:287