‪TYPO3CMS  10.4
AbstractMessage.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 
21 
25 abstract class ‪AbstractMessage implements \JsonSerializable
26 {
27  const ‪NOTICE = -2;
28  const ‪INFO = -1;
29  const ‪OK = 0;
30  const ‪WARNING = 1;
31  const ‪ERROR = 2;
32 
38  protected ‪$title = '';
39 
45  protected ‪$message = '';
46 
52  protected ‪$severity = ‪self::OK;
53 
59  public function ‪getTitle(): string
60  {
61  return ‪$this->title;
62  }
63 
69  public function ‪setTitle(string ‪$title)
70  {
71  $this->title = ‪$title;
72  }
73 
79  public function ‪getMessage(): string
80  {
81  return ‪$this->message;
82  }
83 
89  public function ‪setMessage(string ‪$message)
90  {
91  $this->message = ‪$message;
92  }
93 
99  public function ‪getSeverity(): int
100  {
101  return ‪$this->severity;
102  }
103 
109  public function ‪setSeverity(int ‪$severity = self::OK)
110  {
111  $this->severity = ‪MathUtility::forceIntegerInRange(‪$severity, self::NOTICE, self::ERROR, self::OK);
112  }
113 
120  public function ‪__toString()
121  {
122  $severities = [
123  self::NOTICE => 'NOTICE',
124  self::INFO => 'INFO',
125  self::OK => 'OK',
126  self::WARNING => 'WARNING',
127  self::ERROR => 'ERROR'
128  ];
129  ‪$title = '';
130  if ($this->title !== '') {
131  ‪$title = ' - ' . ‪$this->title;
132  }
133  return $severities[‪$this->severity] . ‪$title . ': ' . ‪$this->message;
134  }
135 
139  public function ‪jsonSerialize(): array
140  {
141  return [
142  'severity' => $this->‪getSeverity(),
143  'title' => $this->‪getTitle(),
144  'message' => $this->‪getMessage(),
145  ];
146  }
147 }
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$message
‪string $message
Definition: AbstractMessage.php:43
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setTitle
‪setTitle(string $title)
Definition: AbstractMessage.php:66
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getSeverity
‪int getSeverity()
Definition: AbstractMessage.php:96
‪TYPO3\CMS\Core\Messaging\AbstractMessage\jsonSerialize
‪array jsonSerialize()
Definition: AbstractMessage.php:136
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$title
‪string $title
Definition: AbstractMessage.php:37
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getMessage
‪string getMessage()
Definition: AbstractMessage.php:76
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Core\Messaging\AbstractMessage\$severity
‪int $severity
Definition: AbstractMessage.php:49
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setMessage
‪setMessage(string $message)
Definition: AbstractMessage.php:86
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Messaging
Definition: AbstractMessage.php:18
‪TYPO3\CMS\Core\Messaging\AbstractMessage\__toString
‪string __toString()
Definition: AbstractMessage.php:117
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\setSeverity
‪setSeverity(int $severity=self::OK)
Definition: AbstractMessage.php:106
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getTitle
‪string getTitle()
Definition: AbstractMessage.php:56