‪TYPO3CMS  ‪main
FlashMessage.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 
22 
27 {
33  protected ‪$storeInSession = false;
34 
43  public function ‪__construct(‪$message, ‪$title = '', ‪$severity = ContextualFeedbackSeverity::OK, ‪$storeInSession = false)
44  {
45  if (is_int(‪$severity)) {
46  // @deprecated int type for $severity deprecated in v12, will change to Severity only in v13.
47  ‪$severity = ContextualFeedbackSeverity::transform(‪$severity) ?? ContextualFeedbackSeverity::OK;
48  }
49  $this->‪setMessage(‪$message);
50  $this->‪setTitle(‪$title);
53  }
54 
61  public static function ‪createFromArray(array $data): self
62  {
63  return GeneralUtility::makeInstance(
64  static::class,
65  (string)$data['message'],
66  (string)($data['title'] ?? ''),
67  ContextualFeedbackSeverity::tryFrom($data['severity']) ?? ContextualFeedbackSeverity::OK,
68  (bool)($data['storeInSession'] ?? false)
69  );
70  }
71 
77  public function ‪isSessionMessage()
78  {
80  }
81 
88  {
89  $this->storeInSession = (bool)‪$storeInSession;
90  }
91 
95  public function ‪jsonSerialize(): array
96  {
97  $data = parent::jsonSerialize();
98  $data['storeInSession'] = ‪$this->storeInSession;
99  return $data;
100  }
101 }
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Messaging\FlashMessage\createFromArray
‪static static createFromArray(array $data)
Definition: FlashMessage.php:60
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$message
‪string $message
Definition: AbstractMessage.php:49
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setTitle
‪setTitle(string $title)
Definition: AbstractMessage.php:57
‪TYPO3\CMS\Core\Messaging\FlashMessage\isSessionMessage
‪bool isSessionMessage()
Definition: FlashMessage.php:76
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$title
‪string $title
Definition: AbstractMessage.php:48
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$severity
‪ContextualFeedbackSeverity $severity
Definition: AbstractMessage.php:50
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setMessage
‪setMessage(string $message)
Definition: AbstractMessage.php:67
‪TYPO3\CMS\Core\Messaging\FlashMessage\$storeInSession
‪bool $storeInSession
Definition: FlashMessage.php:32
‪TYPO3\CMS\Core\Messaging\FlashMessage\setStoreInSession
‪setStoreInSession($storeInSession)
Definition: FlashMessage.php:86
‪TYPO3\CMS\Core\Messaging\FlashMessage\__construct
‪__construct($message, $title='', $severity=ContextualFeedbackSeverity::OK, $storeInSession=false)
Definition: FlashMessage.php:42
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪TYPO3\CMS\Core\Messaging
Definition: AbstractMessage.php:18
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setSeverity
‪setSeverity(int|ContextualFeedbackSeverity $severity=ContextualFeedbackSeverity::OK)
Definition: AbstractMessage.php:87
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Messaging\FlashMessage\jsonSerialize
‪array jsonSerialize()
Definition: FlashMessage.php:94