‪TYPO3CMS  11.5
EnvironmentService.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 
19 
20 use Psr\Http\Message\ServerRequestInterface;
23 
30 {
34  protected ‪$isFrontendMode;
35 
36  public function ‪__construct()
37  {
38  trigger_error(__CLASS__ . ' will be removed in TYPO3 v12, use the PSR-7 Request and the ApplicationType instead.', E_USER_DEPRECATED);
39  }
40 
46  public function ‪isEnvironmentInFrontendMode(): bool
47  {
48  $this->‪initialize();
49  if ($this->isFrontendMode !== null) {
51  }
52  // Frontend mode stays false if backend or cli without request object
53  return (‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
54  && ‪ApplicationType::fromRequest(‪$GLOBALS['TYPO3_REQUEST'])->isFrontend();
55  }
56 
62  public function ‪isEnvironmentInBackendMode(): bool
63  {
64  return !$this->‪isEnvironmentInFrontendMode();
65  }
66 
67  protected function ‪initialize(): void
68  {
69  if ($this->isFrontendMode !== null) {
70  return;
71  }
72  // Frontend mode stays false if backend or cli without request object
73  $this->isFrontendMode = (‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
74  && ‪ApplicationType::fromRequest(‪$GLOBALS['TYPO3_REQUEST'])->isFrontend();
75  }
76 
83  public function ‪setFrontendMode(bool ‪$isFrontendMode): void
84  {
85  $this->isFrontendMode = ‪$isFrontendMode;
86  }
87 }
‪TYPO3\CMS\Core\Http\ApplicationType\fromRequest
‪static static fromRequest(ServerRequestInterface $request)
Definition: ApplicationType.php:62
‪TYPO3\CMS\Extbase\Service\EnvironmentService\initialize
‪initialize()
Definition: EnvironmentService.php:66
‪TYPO3\CMS\Extbase\Service
Definition: CacheService.php:18
‪TYPO3\CMS\Extbase\Service\EnvironmentService\__construct
‪__construct()
Definition: EnvironmentService.php:35
‪TYPO3\CMS\Core\Http\ApplicationType
Definition: ApplicationType.php:52
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:30
‪TYPO3\CMS\Extbase\Service\EnvironmentService\isEnvironmentInFrontendMode
‪bool isEnvironmentInFrontendMode()
Definition: EnvironmentService.php:45
‪TYPO3\CMS\Extbase\Service\EnvironmentService\$isFrontendMode
‪bool null $isFrontendMode
Definition: EnvironmentService.php:33
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Service\EnvironmentService\setFrontendMode
‪setFrontendMode(bool $isFrontendMode)
Definition: EnvironmentService.php:82
‪TYPO3\CMS\Extbase\Service\EnvironmentService\isEnvironmentInBackendMode
‪bool isEnvironmentInBackendMode()
Definition: EnvironmentService.php:61