[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Messaging / AbstractMessage.php
1 <?php
2 namespace TYPO3\CMS\Core\Messaging;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * A class used for any kind of messages.
18 *
19 * @author Ingo Renner <ingo@typo3.org>
20 * @author Benjamin Mack <benni@typo3.org>
21 */
22 abstract class AbstractMessage {
23
24 const NOTICE = -2;
25 const INFO = -1;
26 const OK = 0;
27 const WARNING = 1;
28 const ERROR = 2;
29 /**
30 * The message's title
31 *
32 * @var string
33 */
34 protected $title = '';
35
36 /**
37 * The message
38 *
39 * @var string
40 */
41 protected $message = '';
42
43 /**
44 * The message's severity
45 *
46 * @var integer
47 */
48 protected $severity = self::OK;
49
50 /**
51 * Gets the message's title.
52 *
53 * @return string The message's title.
54 */
55 public function getTitle() {
56 return $this->title;
57 }
58
59 /**
60 * Sets the message's title
61 *
62 * @param string $title The message's title
63 * @return void
64 */
65 public function setTitle($title) {
66 $this->title = (string) $title;
67 }
68
69 /**
70 * Gets the message.
71 *
72 * @return string The message.
73 */
74 public function getMessage() {
75 return $this->message;
76 }
77
78 /**
79 * Sets the message
80 *
81 * @param string $message The message
82 * @return void
83 */
84 public function setMessage($message) {
85 $this->message = (string) $message;
86 }
87
88 /**
89 * Gets the message' severity.
90 *
91 * @return integer The message' severity, must be one of AbstractMessage::INFO or similar contstants
92 */
93 public function getSeverity() {
94 return $this->severity;
95 }
96
97 /**
98 * Sets the message' severity
99 *
100 * @param integer $severity The severity, must be one of AbstractMessage::INFO or similar constants
101 * @return void
102 */
103 public function setSeverity($severity = self::OK) {
104 $this->severity = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($severity, self::NOTICE, self::ERROR, self::OK);
105 }
106
107 /**
108 * Creates a string representation of the message. Useful for command
109 * line use.
110 *
111 * @return string A string representation of the message.
112 */
113 public function __toString() {
114 $severities = array(
115 self::INFO => 'INFO',
116 self::OK => 'OK',
117 self::WARNING => 'WARNING',
118 self::ERROR => 'ERROR'
119 );
120 $title = '';
121 if (!empty($this->title)) {
122 $title = ' - ' . $this->title;
123 }
124 return $severities[$this->severity] . $title . ': ' . $this->message;
125 }
126
127 }