[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Status.php
1 <?php
2 namespace TYPO3\CMS\Reports;
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 representing a certain status
18 *
19 * @author Ingo Renner <ingo@typo3.org>
20 */
21 class Status {
22
23 const NOTICE = -2;
24 const INFO = -1;
25 const OK = 0;
26 const WARNING = 1;
27 const ERROR = 2;
28 /**
29 * @var string
30 */
31 protected $title;
32
33 /**
34 * @var string
35 */
36 protected $value;
37
38 /**
39 * @var string
40 */
41 protected $message;
42
43 /**
44 * @var integer
45 */
46 protected $severity;
47
48 /**
49 * Construct a status
50 *
51 * All values must be given as constructor arguments.
52 * All strings should be localized.
53 *
54 * @param string $title Status title, eg. "Deprecation log"
55 * @param string $value Status value, eg. "Disabled"
56 * @param string $message Optional message further describing the title/value combination
57 * Example:, eg "The deprecation log is important and does foo, to disable it do bar"
58 * @param integer $severity A severity level. Use one of the constants above!
59 */
60 public function __construct($title, $value, $message = '', $severity = self::OK) {
61 $this->title = (string) $title;
62 $this->value = (string) $value;
63 $this->message = (string) $message;
64 $this->severity = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($severity, self::NOTICE, self::ERROR, self::OK);
65 }
66
67 /**
68 * Gets the status' title
69 *
70 * @return string
71 */
72 public function getTitle() {
73 return $this->title;
74 }
75
76 /**
77 * Gets the status' value
78 *
79 * @return string
80 */
81 public function getValue() {
82 return $this->value;
83 }
84
85 /**
86 * Gets the status' message (if any)
87 *
88 * @return string
89 */
90 public function getMessage() {
91 return $this->message;
92 }
93
94 /**
95 * Gets the status' severity
96 *
97 * @return integer
98 */
99 public function getSeverity() {
100 return $this->severity;
101 }
102
103 /**
104 * Creates a string representation of a status.
105 *
106 * @return string String representation of this status.
107 */
108 public function __toString() {
109 $severity = array(
110 self::NOTICE => 'NOTE',
111 self::INFO => 'INFO',
112 self::OK => 'OK',
113 self::WARNING => 'WARN',
114 self::ERROR => 'ERR'
115 );
116 // Max length 80 characters
117 $stringRepresentation = str_pad(('[' . $severity[$this->severity] . ']'), 7) . str_pad($this->title, 40) . ' - ' . substr($this->value, 0, 30);
118 return $stringRepresentation;
119 }
120
121 }