1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2019 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Component\KeyManagement\Analyzer; |
15
|
|
|
|
16
|
|
|
use JsonSerializable; |
17
|
|
|
|
18
|
|
|
class Message implements JsonSerializable |
19
|
|
|
{ |
20
|
|
|
public const SEVERITY_LOW = 'low'; |
21
|
|
|
|
22
|
|
|
public const SEVERITY_MEDIUM = 'medium'; |
23
|
|
|
|
24
|
|
|
public const SEVERITY_HIGH = 'high'; |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $message; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $severity; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Message constructor. |
37
|
|
|
*/ |
38
|
|
|
private function __construct(string $message, string $severity) |
39
|
|
|
{ |
40
|
|
|
$this->message = $message; |
41
|
|
|
$this->severity = $severity; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Creates a message with severity=low. |
46
|
|
|
* |
47
|
|
|
* @return Message |
48
|
|
|
*/ |
49
|
|
|
public static function low(string $message): self |
50
|
|
|
{ |
51
|
|
|
return new self($message, self::SEVERITY_LOW); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Creates a message with severity=medium. |
56
|
|
|
* |
57
|
|
|
* @return Message |
58
|
|
|
*/ |
59
|
|
|
public static function medium(string $message): self |
60
|
|
|
{ |
61
|
|
|
return new self($message, self::SEVERITY_MEDIUM); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Creates a message with severity=high. |
66
|
|
|
* |
67
|
|
|
* @return Message |
68
|
|
|
*/ |
69
|
|
|
public static function high(string $message): self |
70
|
|
|
{ |
71
|
|
|
return new self($message, self::SEVERITY_HIGH); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns the message. |
76
|
|
|
*/ |
77
|
|
|
public function getMessage(): string |
78
|
|
|
{ |
79
|
|
|
return $this->message; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns the severity of the message. |
84
|
|
|
*/ |
85
|
|
|
public function getSeverity(): string |
86
|
|
|
{ |
87
|
|
|
return $this->severity; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function jsonSerialize(): array |
91
|
|
|
{ |
92
|
|
|
return [ |
93
|
|
|
'message' => $this->message, |
94
|
|
|
'severity' => $this->severity, |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|