‪TYPO3CMS  9.5
FlashMessageRendererResolver.php
Go to the documentation of this file.
1 <?php
2 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 
21 
26 {
30  protected ‪$renderer = [
31  'BE' => Renderer\BootstrapRenderer::class,
32  'FE' => Renderer\ListRenderer::class,
33  'CLI' => Renderer\PlaintextRenderer::class,
34  '_default' => Renderer\PlaintextRenderer::class,
35  ];
36 
45  {
46  $rendererClass = $this->‪resolveFlashMessageRenderClass();
47  ‪$renderer = GeneralUtility::makeInstance($rendererClass);
49  throw new \RuntimeException('Renderer ' . get_class(‪$renderer)
50  . ' does not implement FlashMessageRendererInterface', 1476958086);
51  }
52  return ‪$renderer;
53  }
54 
60  protected function ‪resolveFlashMessageRenderClass(): string
61  {
62  $context = $this->‪resolveContext();
63  $renderClass = $this->renderer['_default'];
64 
65  if (!empty($this->renderer[$context])) {
66  $renderClass = $this->renderer[$context];
67  }
68 
69  return $renderClass;
70  }
71 
81  protected function ‪resolveContext(): string
82  {
83  $context = '';
84  if (‪Environment::isCli()) {
85  $context = 'CLI';
86  } elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
87  $context = 'BE';
88  } elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_FE) {
89  $context = 'FE';
90  }
91  return $context;
92  }
93 }
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolveFlashMessageRenderClass
‪string resolveFlashMessageRenderClass()
Definition: FlashMessageRendererResolver.php:59
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolve
‪FlashMessageRendererInterface resolve()
Definition: FlashMessageRendererResolver.php:43
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver
Definition: FlashMessageRendererResolver.php:26
‪TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface
Definition: FlashMessageRendererInterface.php:24
‪TYPO3\CMS\Core\Messaging
Definition: AbstractMessage.php:3
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\resolveContext
‪string resolveContext()
Definition: FlashMessageRendererResolver.php:80
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver\$renderer
‪array $renderer
Definition: FlashMessageRendererResolver.php:29
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:127