‪TYPO3CMS  10.4
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 
26 
31 {
35  protected ‪$renderer = [
36  'BE' => BootstrapRenderer::class,
37  'FE' => ListRenderer::class,
38  'CLI' => PlaintextRenderer::class,
39  '_default' => PlaintextRenderer::class,
40  ];
41 
50  {
51  $rendererClass = $this->‪resolveFlashMessageRenderClass();
52  ‪$renderer = GeneralUtility::makeInstance($rendererClass);
54  throw new \RuntimeException('Renderer ' . get_class(‪$renderer)
55  . ' does not implement FlashMessageRendererInterface', 1476958086);
56  }
57  return ‪$renderer;
58  }
59 
65  protected function ‪resolveFlashMessageRenderClass(): string
66  {
67  $context = $this->‪resolveContext();
68  $renderClass = $this->renderer['_default'];
69 
70  if (!empty($this->renderer[$context])) {
71  $renderClass = $this->renderer[$context];
72  }
73 
74  return $renderClass;
75  }
76 
86  protected function ‪resolveContext(): string
87  {
88  $context = '';
89  if (‪Environment::isCli()) {
90  $context = 'CLI';
91  } elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
92  $context = 'BE';
93  } elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_FE) {
94  $context = 'FE';
95  }
96  return $context;
97  }
98 }
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolveFlashMessageRenderClass
‪string resolveFlashMessageRenderClass()
Definition: FlashMessageRendererResolver.php:64
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolve
‪FlashMessageRendererInterface resolve()
Definition: FlashMessageRendererResolver.php:48
‪TYPO3\CMS\Core\Messaging\Renderer\PlaintextRenderer
Definition: PlaintextRenderer.php:42
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver
Definition: FlashMessageRendererResolver.php:31
‪TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface
Definition: FlashMessageRendererInterface.php:26
‪TYPO3\CMS\Core\Messaging\Renderer\ListRenderer
Definition: ListRenderer.php:31
‪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:85
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\$renderer
‪array $renderer
Definition: FlashMessageRendererResolver.php:34
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:154