43093ef978b4506839bff670a6fbd9f3633e9751
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Status.php
1 <?php
2 namespace TYPO3\CMS\Reports;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * A class representing a certain status
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 */
31 class Status {
32
33 const NOTICE = -2;
34 const INFO = -1;
35 const OK = 0;
36 const WARNING = 1;
37 const ERROR = 2;
38 /**
39 * @var string
40 */
41 protected $title;
42
43 /**
44 * @var string
45 */
46 protected $value;
47
48 /**
49 * @var string
50 */
51 protected $message;
52
53 /**
54 * @var integer
55 */
56 protected $severity;
57
58 /**
59 * Construct a status
60 *
61 * All values must be given as constructor arguments.
62 * All strings should be localized.
63 *
64 * @param string $title Status title, eg. "Deprecation log"
65 * @param string $value Status value, eg. "Disabled"
66 * @param string $message Optional message further describing the title/value combination
67 * Example:, eg "The deprecation log is important and does foo, to disable it do bar"
68 * @param integer $severity A severity level. Use one of the constants above!
69 */
70 public function __construct($title, $value, $message = '', $severity = self::OK) {
71 $this->title = (string) $title;
72 $this->value = (string) $value;
73 $this->message = (string) $message;
74 $this->severity = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($severity, self::NOTICE, self::ERROR, self::OK);
75 }
76
77 /**
78 * Gets the status' title
79 *
80 * @return string
81 */
82 public function getTitle() {
83 return $this->title;
84 }
85
86 /**
87 * Gets the status' value
88 *
89 * @return string
90 */
91 public function getValue() {
92 return $this->value;
93 }
94
95 /**
96 * Gets the status' message (if any)
97 *
98 * @return string
99 */
100 public function getMessage() {
101 return $this->message;
102 }
103
104 /**
105 * Gets the status' severity
106 *
107 * @return integer
108 */
109 public function getSeverity() {
110 return $this->severity;
111 }
112
113 /**
114 * Creates a string representation of a status.
115 *
116 * @return string String representation of this status.
117 */
118 public function __toString() {
119 $severity = array(
120 self::NOTICE => 'NOTE',
121 self::INFO => 'INFO',
122 self::OK => 'OK',
123 self::WARNING => 'WARN',
124 self::ERROR => 'ERR'
125 );
126 // Max length 80 characters
127 $stringRepresentation = str_pad(('[' . $severity[$this->severity] . ']'), 7) . str_pad($this->title, 40) . ' - ' . substr($this->value, 0, 30);
128 return $stringRepresentation;
129 }
130
131 }