‪TYPO3CMS  ‪main
ApplicationType.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\Http;
19 
20 use Psr\Http\Message\ServerRequestInterface;
21 use RuntimeException;
23 
55 enum ‪ApplicationType: string
56 {
57  // SystemEnvironmentBuilder::REQUESTTYPE_BE
58  case BACKEND = 'backend';
59  // SystemEnvironmentBuilder::REQUESTTYPE_FE
60  case FRONTEND = 'frontend';
61 
67  public static function ‪fromRequest(ServerRequestInterface $request): self
68  {
69  $type = $request->getAttribute('applicationType');
70  if (!is_int($type)) {
71  // Request object has no valid type. Type is set by the Frontend / Backend / Install
72  // application. If it's missing, we've not been called behind a legit TYPO3 application object.
73  // This is bogus, we throw a generic RuntimeException that should not be caught.
74  throw new \RuntimeException('No valid attribute "applicationType" found in request object.', 1606222812);
75  }
77  return self::FRONTEND;
78  }
80  return self::BACKEND;
81  }
82  throw new \LogicException('Could not resolve application type to either frontend or backend', 1678875015);
83  }
84 
85  public function abbreviate(): ?string
86  {
87  return self::abbreviations()[$this] ?? null;
88  }
89 
90  public function isFrontend(): bool
91  {
92  return $this === self::FRONTEND;
93  }
94 
95  public function isBackend(): bool
96  {
97  return $this === self::BACKEND;
98  }
99 
100  private static function abbreviations(): \WeakMap
101  {
102  $map = new \WeakMap();
103  $map[self::FRONTEND] = 'FE';
104  $map[self::BACKEND] = 'BE';
105  return $map;
106  }
107 }
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Core\Http\fromRequest
‪@ fromRequest
Definition: ApplicationType.php:67
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_FE
‪const REQUESTTYPE_FE
Definition: SystemEnvironmentBuilder.php:43
‪TYPO3\CMS\Core\Http\ApplicationType
‪ApplicationType
Definition: ApplicationType.php:56
‪TYPO3\CMS\Core\Http
Definition: AbstractApplication.php:18