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