TYPO3 CMS  TYPO3_8-7
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
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 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31