TYPO3 CMS  TYPO3_8-7
FlashMessageFinisher.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 originated from the Neos.Form package (www.neos.io)
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
27 
48 {
49 
53  protected $defaultOptions = [
54  'messageBody' => null,
55  'messageTitle' => '',
56  'messageArguments' => [],
57  'messageCode' => null,
58  'severity' => AbstractMessage::OK,
59  ];
60 
67  protected function executeInternal()
68  {
69  $messageBody = $this->parseOption('messageBody');
70  if (!is_string($messageBody)) {
71  throw new FinisherException(sprintf('The message body must be of type string, "%s" given.', gettype($messageBody)), 1335980069);
72  }
73  $messageTitle = $this->parseOption('messageTitle');
74  $messageArguments = $this->parseOption('messageArguments');
75  $messageCode = $this->parseOption('messageCode');
76  $severity = $this->parseOption('severity');
77  switch ($severity) {
79  $message = $this->objectManager->get(Notice::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
80  break;
82  $message = $this->objectManager->get(Warning::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
83  break;
85  $message = $this->objectManager->get(Error::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
86  break;
87  default:
88  $message = $this->objectManager->get(Message::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
89  break;
90  }
91 
92  $flashMessage = $this->objectManager->get(
93  FlashMessage::class,
94  $message->render(),
95  $message->getTitle(),
96  $severity,
97  true
98  );
99 
100  $this->finisherContext->getControllerContext()->getFlashMessageQueue()->addMessage($flashMessage);
101  }
102 }