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