|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace Jaxon\Request\Call\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Jaxon\Request\Call\Call; |
|
6
|
|
|
use Jaxon\Request\Call\Parameter; |
|
7
|
|
|
|
|
8
|
|
|
use function array_map; |
|
9
|
|
|
use function func_get_args; |
|
10
|
|
|
|
|
11
|
|
|
trait CallMessageTrait |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The type of the message to show |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $sMessageType = 'warning'; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The arguments of the elseShow() call |
|
22
|
|
|
* |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $aMessageArgs = []; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Set the message if the condition to the call is not met |
|
29
|
|
|
* |
|
30
|
|
|
* The first parameter is the message to show. The second allows inserting data from |
|
31
|
|
|
* the webpage in the message using positional placeholders. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $sMessageType The message to show |
|
|
|
|
|
|
34
|
|
|
* @param array $aMessageArgs |
|
|
|
|
|
|
35
|
|
|
* |
|
36
|
|
|
* @return Call |
|
37
|
|
|
*/ |
|
38
|
|
|
private function setMessage(string $sMessageType, array $aMessageArgs): Call |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
$this->sMessageType = $sMessageType; |
|
41
|
|
|
$this->aMessageArgs = array_map(function($xParameter) { |
|
42
|
|
|
return Parameter::make($xParameter); |
|
43
|
|
|
}, $aMessageArgs); |
|
44
|
|
|
return $this; |
|
|
|
|
|
|
45
|
|
|
} |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Show a message if the condition to the call is not met |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $sMessage The message to show |
|
|
|
|
|
|
51
|
|
|
* |
|
52
|
|
|
* @return Call |
|
53
|
|
|
*/ |
|
54
|
|
|
public function elseShow(string $sMessage): Call |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->setMessage('warning', func_get_args()); |
|
57
|
|
|
} |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Show an information message if the condition to the call is not met |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $sMessage The message to show |
|
|
|
|
|
|
63
|
|
|
* |
|
64
|
|
|
* @return Call |
|
65
|
|
|
*/ |
|
66
|
|
|
public function elseInfo(string $sMessage): Call |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->setMessage('info', func_get_args()); |
|
69
|
|
|
} |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Show a success message if the condition to the call is not met |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $sMessage The message to show |
|
|
|
|
|
|
75
|
|
|
* |
|
76
|
|
|
* @return Call |
|
77
|
|
|
*/ |
|
78
|
|
|
public function elseSuccess(string $sMessage): Call |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->setMessage('success', func_get_args()); |
|
81
|
|
|
} |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Show a warning message if the condition to the call is not met |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $sMessage The message to show |
|
|
|
|
|
|
87
|
|
|
* |
|
88
|
|
|
* @return Call |
|
89
|
|
|
*/ |
|
90
|
|
|
public function elseWarning(string $sMessage): Call |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->setMessage('warning', func_get_args()); |
|
93
|
|
|
} |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Show an error message if the condition to the call is not met |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $sMessage The message to show |
|
|
|
|
|
|
99
|
|
|
* |
|
100
|
|
|
* @return Call |
|
101
|
|
|
*/ |
|
102
|
|
|
public function elseError(string $sMessage): Call |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->setMessage('error', func_get_args()); |
|
105
|
|
|
} |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|