‪TYPO3CMS  11.5
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 
43 {
48  protected static ‪$supportedCgiServerApis = [
49  'fpm-fcgi',
50  'cgi',
51  'isapi',
52  'cgi-fcgi',
53  'srv', // HHVM with fastcgi
54  ];
55 
59  protected static ‪$cli;
60 
64  protected static ‪$composerMode;
65 
69  protected static ‪$context;
70 
74  protected static ‪$projectPath;
75 
79  protected static ‪$composerRootPath;
80 
84  protected static ‪$publicPath;
85 
89  protected static ‪$currentScript;
90 
94  protected static ‪$os;
95 
99  protected static ‪$varPath;
100 
104  protected static ‪$configPath;
105 
122  public static function ‪initialize(
124  bool ‪$cli,
125  bool ‪$composerMode,
126  string ‪$projectPath,
127  string ‪$publicPath,
128  string ‪$varPath,
129  string ‪$configPath,
130  string ‪$currentScript,
131  string ‪$os
132  ) {
133  self::$cli = ‪$cli;
134  self::$composerMode = ‪$composerMode;
135  self::$context = ‪$context;
136  self::$projectPath = ‪$projectPath;
137  self::$composerRootPath = ‪$composerMode ? ‪PathUtility::getCanonicalPath(InstalledVersions::getRootPackage()['install_path']) : '';
138  self::$publicPath = ‪$publicPath;
139  self::$varPath = ‪$varPath;
140  self::$configPath = ‪$configPath;
141  self::$currentScript = ‪$currentScript;
142  self::$os = ‪$os;
143  }
144 
152  public static function ‪getContext(): ‪ApplicationContext
153  {
154  return ‪self::$context;
155  }
156 
163  public static function ‪isComposerMode(): bool
164  {
165  return ‪self::$composerMode;
166  }
167 
173  public static function ‪isCli(): bool
174  {
175  return ‪self::$cli;
176  }
177 
188  public static function ‪getProjectPath(): string
189  {
190  return ‪self::$projectPath;
191  }
192 
202  public static function ‪getComposerRootPath(): string
203  {
204  if (self::$composerMode === false) {
205  throw new \BadMethodCallException('Composer root path is only available in Composer mode', 1631700480);
206  }
207 
209  }
210 
217  public static function ‪getPublicPath(): string
218  {
219  return ‪self::$publicPath;
220  }
221 
229  public static function ‪getVarPath(): string
230  {
231  return ‪self::$varPath;
232  }
233 
247  public static function ‪getConfigPath(): string
248  {
249  return ‪self::$configPath;
250  }
251 
257  public static function ‪getCurrentScript(): string
258  {
260  }
261 
273  public static function ‪getLabelsPath(): string
274  {
275  if (self::$publicPath === self::$projectPath) {
276  return ‪self::getPublicPath() . '/typo3conf/l10n';
277  }
278  return ‪self::getVarPath() . '/labels';
279  }
280 
287  public static function ‪getBackendPath(): string
288  {
289  return ‪self::getPublicPath() . '/typo3';
290  }
291 
298  public static function ‪getFrameworkBasePath(): string
299  {
300  return ‪self::getPublicPath() . '/typo3/sysext';
301  }
302 
308  public static function ‪getExtensionsPath(): string
309  {
310  return ‪self::getPublicPath() . '/typo3conf/ext';
311  }
312 
319  public static function ‪getLegacyConfigPath(): string
320  {
321  return ‪self::getPublicPath() . '/typo3conf';
322  }
323 
329  public static function ‪isWindows(): bool
330  {
331  return self::$os === 'WINDOWS';
332  }
333 
339  public static function ‪isUnix(): bool
340  {
341  return self::$os === 'UNIX';
342  }
343 
349  public static function ‪isRunningOnCgiServer(): bool
350  {
351  return in_array(PHP_SAPI, self::$supportedCgiServerApis, true);
352  }
353 
354  public static function ‪usesCgiFixPathInfo(): bool
355  {
356  return !empty(ini_get('cgi.fix_pathinfo'));
357  }
358 
364  public static function ‪toArray(): array
365  {
366  return [
367  'context' => (string)self::getContext(),
368  'cli' => ‪self::isCli(),
369  'projectPath' => ‪self::getProjectPath(),
370  'publicPath' => ‪self::getPublicPath(),
371  'varPath' => ‪self::getVarPath(),
372  'configPath' => ‪self::getConfigPath(),
373  'currentScript' => ‪self::getCurrentScript(),
374  'os' => ‪self::isWindows() ? 'WINDOWS' : 'UNIX',
375  ];
376  }
377 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:206
‪TYPO3\CMS\Core\Core\Environment\$composerMode
‪static bool $composerMode
Definition: Environment.php:61
‪TYPO3\CMS\Core\Core\Environment\isRunningOnCgiServer
‪static bool isRunningOnCgiServer()
Definition: Environment.php:338
‪TYPO3\CMS\Core\Core\Environment\getLabelsPath
‪static string getLabelsPath()
Definition: Environment.php:262
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:39
‪TYPO3\CMS\Core\Core\Environment\getComposerRootPath
‪static string getComposerRootPath()
Definition: Environment.php:191
‪TYPO3\CMS\Core\Core\Environment\isUnix
‪static bool isUnix()
Definition: Environment.php:328
‪TYPO3\CMS\Core\Core\Environment\$currentScript
‪static string $currentScript
Definition: Environment.php:81
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static bool isWindows()
Definition: Environment.php:318
‪TYPO3\CMS\Core\Core\Environment\getCurrentScript
‪static string getCurrentScript()
Definition: Environment.php:246
‪TYPO3\CMS\Core\Core\Environment\$projectPath
‪static string $projectPath
Definition: Environment.php:69
‪TYPO3\CMS\Core\Utility\PathUtility\getCanonicalPath
‪static string getCanonicalPath($path)
Definition: PathUtility.php:380
‪TYPO3\CMS\Core\Core\Environment\$cli
‪static bool $cli
Definition: Environment.php:57
‪TYPO3\CMS\Core\Core\Environment\getFrameworkBasePath
‪static string getFrameworkBasePath()
Definition: Environment.php:287
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static ApplicationContext getContext()
Definition: Environment.php:141
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:177
‪TYPO3\CMS\Core\Core\Environment\$os
‪static string $os
Definition: Environment.php:85
‪TYPO3\CMS\Core\Core\Environment\usesCgiFixPathInfo
‪static usesCgiFixPathInfo()
Definition: Environment.php:343
‪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:111
‪TYPO3\CMS\Core\Core\Environment\getBackendPath
‪static string getBackendPath()
Definition: Environment.php:276
‪TYPO3\CMS\Core\Core\Environment\$publicPath
‪static string $publicPath
Definition: Environment.php:77
‪TYPO3\CMS\Core\Core\Environment\$varPath
‪static string $varPath
Definition: Environment.php:89
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:152
‪TYPO3\CMS\Core\Core\Environment\toArray
‪static array toArray()
Definition: Environment.php:353
‪TYPO3\CMS\Core\Core\Environment\$composerRootPath
‪static string $composerRootPath
Definition: Environment.php:73
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Core\Core
Definition: ApplicationContext.php:16
‪TYPO3\CMS\Core\Core\Environment\$context
‪static ApplicationContext $context
Definition: Environment.php:65
‪TYPO3\CMS\Core\Core\Environment\$supportedCgiServerApis
‪static array $supportedCgiServerApis
Definition: Environment.php:47
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static string getConfigPath()
Definition: Environment.php:236
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:162
‪TYPO3\CMS\Core\Core\Environment\$configPath
‪static string $configPath
Definition: Environment.php:93
‪TYPO3\CMS\Core\Core\Environment\getLegacyConfigPath
‪static string getLegacyConfigPath()
Definition: Environment.php:308
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:218
‪TYPO3\CMS\Core\Core\Environment\getExtensionsPath
‪static string getExtensionsPath()
Definition: Environment.php:297