1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * AlertLibrary.php |
||||||
5 | * |
||||||
6 | * Implements the dialog message and question features using the js alert and confirm functions. |
||||||
7 | * |
||||||
8 | * @package jaxon-core |
||||||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||||
9 | * @author Thierry Feuzeu <[email protected]> |
||||||
10 | * @copyright 2016 Thierry Feuzeu <[email protected]> |
||||||
11 | * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
||||||
12 | * @link https://github.com/jaxon-php/jaxon-core |
||||||
13 | */ |
||||||
0 ignored issues
–
show
|
|||||||
14 | |||||||
15 | namespace Jaxon\App\Dialog\Library; |
||||||
16 | |||||||
17 | use Jaxon\App\Dialog\LibraryInterface; |
||||||
18 | use Jaxon\App\Dialog\MessageInterface; |
||||||
19 | use Jaxon\App\Dialog\QuestionInterface; |
||||||
20 | |||||||
21 | class AlertLibrary implements LibraryInterface, MessageInterface, QuestionInterface |
||||||
0 ignored issues
–
show
|
|||||||
22 | { |
||||||
23 | use DialogLibraryTrait; |
||||||
24 | |||||||
25 | /** |
||||||
26 | * Get the library name |
||||||
27 | * |
||||||
28 | * @return string |
||||||
29 | */ |
||||||
30 | public function getName(): string |
||||||
0 ignored issues
–
show
|
|||||||
31 | { |
||||||
32 | return ''; // No name |
||||||
33 | } |
||||||
0 ignored issues
–
show
|
|||||||
34 | |||||||
35 | /** |
||||||
36 | * Get the script which makes a call only if the user answers yes to the given question |
||||||
37 | * |
||||||
38 | * @param string $sQuestion |
||||||
0 ignored issues
–
show
|
|||||||
39 | * @param string $sYesScript |
||||||
0 ignored issues
–
show
|
|||||||
40 | * @param string $sNoScript |
||||||
0 ignored issues
–
show
|
|||||||
41 | * |
||||||
42 | * @return string |
||||||
43 | */ |
||||||
44 | public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string |
||||||
45 | { |
||||||
46 | return empty($sNoScript) ? 'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}' : |
||||||
0 ignored issues
–
show
|
|||||||
47 | 'if(confirm(' . $sQuestion . ')){' . $sYesScript . ';}else{' . $sNoScript . ';}'; |
||||||
48 | } |
||||||
0 ignored issues
–
show
|
|||||||
49 | |||||||
50 | /** |
||||||
51 | * Print an alert message. |
||||||
52 | * |
||||||
53 | * @param string $sMessage The text of the message |
||||||
0 ignored issues
–
show
|
|||||||
54 | * @param string $sTitle The title of the message |
||||||
0 ignored issues
–
show
|
|||||||
55 | * |
||||||
56 | * @return string |
||||||
57 | */ |
||||||
58 | private function alert(string $sMessage, string $sTitle): string |
||||||
59 | { |
||||||
60 | if(!empty($sTitle)) |
||||||
61 | { |
||||||
62 | $sMessage = '<b>' . $sTitle . '</b><br/>' . $sMessage; |
||||||
63 | } |
||||||
64 | if($this->returnCode()) |
||||||
65 | { |
||||||
66 | return 'alert(' . $sMessage . ')'; |
||||||
67 | } |
||||||
68 | $this->xResponse->alert($sMessage, $sTitle); |
||||||
0 ignored issues
–
show
The call to
Jaxon\Response\Response::alert() has too many arguments starting with $sTitle .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.
Loading history...
|
|||||||
69 | return ''; |
||||||
70 | } |
||||||
0 ignored issues
–
show
|
|||||||
71 | |||||||
72 | /** |
||||||
73 | * Print a success message. |
||||||
74 | * |
||||||
75 | * @param string $sMessage The text of the message |
||||||
0 ignored issues
–
show
|
|||||||
76 | * @param string $sTitle The title of the message |
||||||
0 ignored issues
–
show
|
|||||||
77 | * |
||||||
78 | * @return string |
||||||
79 | */ |
||||||
80 | public function success(string $sMessage, string $sTitle = ''): string |
||||||
81 | { |
||||||
82 | return $this->alert($sMessage, $sTitle); |
||||||
83 | } |
||||||
0 ignored issues
–
show
|
|||||||
84 | |||||||
85 | /** |
||||||
86 | * Print an information message. |
||||||
87 | * |
||||||
88 | * @param string $sMessage The text of the message |
||||||
0 ignored issues
–
show
|
|||||||
89 | * @param string $sTitle The title of the message |
||||||
0 ignored issues
–
show
|
|||||||
90 | * |
||||||
91 | * @return string |
||||||
92 | */ |
||||||
93 | public function info(string $sMessage, string $sTitle = ''): string |
||||||
94 | { |
||||||
95 | return $this->alert($sMessage, $sTitle); |
||||||
96 | } |
||||||
0 ignored issues
–
show
|
|||||||
97 | |||||||
98 | /** |
||||||
99 | * Print a warning message. |
||||||
100 | * |
||||||
101 | * @param string $sMessage The text of the message |
||||||
0 ignored issues
–
show
|
|||||||
102 | * @param string $sTitle The title of the message |
||||||
0 ignored issues
–
show
|
|||||||
103 | * |
||||||
104 | * @return string |
||||||
105 | */ |
||||||
106 | public function warning(string $sMessage, string $sTitle = ''): string |
||||||
107 | { |
||||||
108 | return $this->alert($sMessage, $sTitle); |
||||||
109 | } |
||||||
0 ignored issues
–
show
|
|||||||
110 | |||||||
111 | /** |
||||||
112 | * Print an error message. |
||||||
113 | * |
||||||
114 | * @param string $sMessage The text of the message |
||||||
0 ignored issues
–
show
|
|||||||
115 | * @param string $sTitle The title of the message |
||||||
0 ignored issues
–
show
|
|||||||
116 | * |
||||||
117 | * @return string |
||||||
118 | */ |
||||||
119 | public function error(string $sMessage, string $sTitle = ''): string |
||||||
120 | { |
||||||
121 | return $this->alert($sMessage, $sTitle); |
||||||
122 | } |
||||||
0 ignored issues
–
show
|
|||||||
123 | } |
||||||
124 |