‪TYPO3CMS  9.5
AbstractMessage.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 
19 
23 abstract class ‪AbstractMessage implements \JsonSerializable
24 {
25  const ‪NOTICE = -2;
26  const ‪INFO = -1;
27  const ‪OK = 0;
28  const ‪WARNING = 1;
29  const ‪ERROR = 2;
30 
36  protected ‪$title = '';
37 
43  protected ‪$message = '';
44 
50  protected ‪$severity = ‪self::OK;
51 
57  public function ‪getTitle(): string
58  {
59  return ‪$this->title;
60  }
61 
67  public function ‪setTitle(string ‪$title)
68  {
69  $this->title = ‪$title;
70  }
71 
77  public function ‪getMessage(): string
78  {
79  return ‪$this->message;
80  }
81 
87  public function ‪setMessage(string ‪$message)
88  {
89  $this->message = ‪$message;
90  }
91 
97  public function ‪getSeverity(): int
98  {
99  return ‪$this->severity;
100  }
101 
107  public function ‪setSeverity(int ‪$severity = self::OK)
108  {
109  $this->severity = ‪MathUtility::forceIntegerInRange(‪$severity, self::NOTICE, self::ERROR, self::OK);
110  }
111 
118  public function ‪__toString()
119  {
120  $severities = [
121  self::NOTICE => 'NOTICE',
122  self::INFO => 'INFO',
123  self::OK => 'OK',
124  self::WARNING => 'WARNING',
125  self::ERROR => 'ERROR'
126  ];
127  ‪$title = '';
128  if ($this->title !== '') {
129  ‪$title = ' - ' . ‪$this->title;
130  }
131  return $severities[‪$this->severity] . ‪$title . ': ' . ‪$this->message;
132  }
133 
137  public function ‪jsonSerialize(): array
138  {
139  return [
140  'severity' => $this->‪getSeverity(),
141  'title' => $this->‪getTitle(),
142  'message' => $this->‪getMessage(),
143  ];
144  }
145 }
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:24
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$message
‪string $message
Definition: AbstractMessage.php:41
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setTitle
‪setTitle(string $title)
Definition: AbstractMessage.php:64
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getSeverity
‪int getSeverity()
Definition: AbstractMessage.php:94
‪TYPO3\CMS\Core\Messaging\AbstractMessage\jsonSerialize
‪array jsonSerialize()
Definition: AbstractMessage.php:134
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$title
‪string $title
Definition: AbstractMessage.php:35
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getMessage
‪string getMessage()
Definition: AbstractMessage.php:74
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$severity
‪int $severity
Definition: AbstractMessage.php:47
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setMessage
‪setMessage(string $message)
Definition: AbstractMessage.php:84
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Messaging
Definition: AbstractMessage.php:3
‪TYPO3\CMS\Core\Messaging\AbstractMessage\__toString
‪string __toString()
Definition: AbstractMessage.php:115
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setSeverity
‪setSeverity(int $severity=self::OK)
Definition: AbstractMessage.php:104
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getTitle
‪string getTitle()
Definition: AbstractMessage.php:54