‪TYPO3CMS  11.5
FlashMessageRendererResolver.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 
28 
33 {
37  protected ‪$renderer = [
38  'BE' => BootstrapRenderer::class,
39  'FE' => ListRenderer::class,
40  'CLI' => PlaintextRenderer::class,
41  '_default' => PlaintextRenderer::class,
42  ];
43 
52  {
53  $rendererClass = $this->‪resolveFlashMessageRenderClass();
54  ‪$renderer = GeneralUtility::makeInstance($rendererClass);
56  throw new \RuntimeException('Renderer ' . get_class(‪$renderer)
57  . ' does not implement FlashMessageRendererInterface', 1476958086);
58  }
59  return ‪$renderer;
60  }
61 
67  protected function ‪resolveFlashMessageRenderClass(): string
68  {
69  $context = $this->‪resolveContext();
70  $renderClass = $this->renderer['_default'];
71 
72  if (!empty($this->renderer[$context])) {
73  $renderClass = $this->renderer[$context];
74  }
75 
76  return $renderClass;
77  }
78 
88  protected function ‪resolveContext(): string
89  {
90  $context = '';
91  $request = ‪$GLOBALS['TYPO3_REQUEST'] ?? null;
92  if (‪Environment::isCli()) {
93  $context = 'CLI';
94  } elseif ($request instanceof ‪ServerRequest && ‪ApplicationType::fromRequest($request)->isBackend()) {
95  $context = 'BE';
96  } elseif ($request instanceof ‪ServerRequest && ‪ApplicationType::fromRequest($request)->isFrontend()) {
97  $context = 'FE';
98  }
99  return $context;
100  }
101 }
‪TYPO3\CMS\Core\Http\ApplicationType\fromRequest
‪static static fromRequest(ServerRequestInterface $request)
Definition: ApplicationType.php:62
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolveFlashMessageRenderClass
‪string resolveFlashMessageRenderClass()
Definition: FlashMessageRendererResolver.php:66
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolve
‪FlashMessageRendererInterface resolve()
Definition: FlashMessageRendererResolver.php:50
‪TYPO3\CMS\Core\Messaging\Renderer\PlaintextRenderer
Definition: PlaintextRenderer.php:42
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver
Definition: FlashMessageRendererResolver.php:33
‪TYPO3\CMS\Core\Http\ApplicationType
Definition: ApplicationType.php:52
‪TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface
Definition: FlashMessageRendererInterface.php:26
‪TYPO3\CMS\Core\Messaging\Renderer\ListRenderer
Definition: ListRenderer.php:31
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer
Definition: BootstrapRenderer.php:30
‪TYPO3\CMS\Core\Messaging
Definition: AbstractMessage.php:18
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolveContext
‪string resolveContext()
Definition: FlashMessageRendererResolver.php:87
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\$renderer
‪array $renderer
Definition: FlashMessageRendererResolver.php:36
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:162