‪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 
256  public static function ‪getFrameworkBasePath(): string
257  {
258  return ‪self::getPublicPath() . '/typo3/sysext';
259  }
260 
264  public static function ‪getExtensionsPath(): string
265  {
266  return ‪self::getPublicPath() . '/typo3conf/ext';
267  }
268 
279  public static function ‪getLegacyConfigPath(): string
280  {
281  return ‪self::getPublicPath() . '/typo3conf';
282  }
283 
287  public static function ‪isWindows(): bool
288  {
289  return self::$os === 'WINDOWS';
290  }
291 
295  public static function ‪isUnix(): bool
296  {
297  return self::$os === 'UNIX';
298  }
299 
303  public static function ‪isRunningOnCgiServer(): bool
304  {
305  return in_array(PHP_SAPI, self::$supportedCgiServerApis, true);
306  }
307 
308  public static function ‪usesCgiFixPathInfo(): bool
309  {
310  return !empty(ini_get('cgi.fix_pathinfo'));
311  }
312 
316  public static function ‪toArray(): array
317  {
318  return [
319  'context' => (string)self::getContext(),
320  'cli' => ‪self::isCli(),
321  'projectPath' => ‪self::getProjectPath(),
322  'publicPath' => ‪self::getPublicPath(),
323  'varPath' => ‪self::getVarPath(),
324  'configPath' => ‪self::getConfigPath(),
325  'currentScript' => ‪self::getCurrentScript(),
326  'os' => ‪self::isWindows() ? 'WINDOWS' : 'UNIX',
327  ];
328  }
329 }
‪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:284
‪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:253
‪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:305
‪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\getLegacyConfigPath
‪static getLegacyConfigPath()
Definition: Environment.php:268
‪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:297
‪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:245
‪TYPO3\CMS\Core\Core\Environment\$composerRootPath
‪static string $composerRootPath
Definition: Environment.php:71
‪TYPO3\CMS\Core\Core\Environment\isRunningOnCgiServer
‪static isRunningOnCgiServer()
Definition: Environment.php:292
‪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:276