‪TYPO3CMS  11.5
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 
51 final class ‪ApplicationType
52 {
53  private int ‪$type = 0;
54 
62  public static function ‪fromRequest(ServerRequestInterface $request): self
63  {
64  ‪$type = $request->getAttribute('applicationType');
65  if (!is_int(‪$type)) {
66  // Request object has no valid type. Type is set by the Frontend / Backend / Install
67  // application. If it's missing, we've not been called behind a legit TYPO3 application object.
68  // This is bogus, we throw a generic RuntimeException that should not be caught.
69  throw new RuntimeException('No valid attribute "applicationType" found in request object.', 1606222812);
70  }
71  return new self(‪$type);
72  }
73 
74  private function ‪__construct(int ‪$type)
75  {
76  $this->type = ‪$type;
77  }
78 
79  public function ‪isFrontend(): bool
80  {
81  return (bool)($this->type & ‪SystemEnvironmentBuilder::REQUESTTYPE_FE);
82  }
83 
84  public function ‪isBackend(): bool
85  {
86  return (bool)($this->type & ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
87  }
88 }
‪TYPO3\CMS\Core\Http\ApplicationType\fromRequest
‪static static fromRequest(ServerRequestInterface $request)
Definition: ApplicationType.php:62
‪TYPO3\CMS\Core\Http\ApplicationType\isFrontend
‪isFrontend()
Definition: ApplicationType.php:79
‪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\ApplicationType
Definition: ApplicationType.php:52
‪TYPO3\CMS\Core\Http\ApplicationType\isBackend
‪isBackend()
Definition: ApplicationType.php:84
‪TYPO3\CMS\Core\Http\ApplicationType\$type
‪int $type
Definition: ApplicationType.php:53
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_FE
‪const REQUESTTYPE_FE
Definition: SystemEnvironmentBuilder.php:43
‪TYPO3\CMS\Core\Http\ApplicationType\__construct
‪__construct(int $type)
Definition: ApplicationType.php:74
‪TYPO3\CMS\Core\Http
Definition: AbstractApplication.php:18