These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Admin\View\Helper; |
||
3 | |||
4 | use Redaxscript\Admin; |
||
5 | use Redaxscript\Html; |
||
6 | use Redaxscript\Language; |
||
7 | use Redaxscript\Module; |
||
8 | use function array_key_exists; |
||
9 | use function array_replace_recursive; |
||
10 | use function is_array; |
||
11 | |||
12 | /** |
||
13 | * helper class to create the admin notification |
||
14 | * |
||
15 | * @since 4.0.0 |
||
16 | * |
||
17 | * @package Redaxscript |
||
18 | * @category View |
||
19 | * @author Henry Ruhs |
||
20 | */ |
||
21 | |||
22 | class Notification implements Admin\View\ViewInterface |
||
23 | { |
||
24 | /** |
||
25 | * instance of the language class |
||
26 | * |
||
27 | * @var Language |
||
28 | */ |
||
29 | |||
30 | protected $_language; |
||
31 | |||
32 | /** |
||
33 | * array of the notification |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | |||
38 | protected $_notificationArray = []; |
||
39 | |||
40 | /** |
||
41 | * options of the notification |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | |||
46 | protected $_optionArray = |
||
47 | [ |
||
48 | 'className' => |
||
49 | [ |
||
50 | 'list' => 'rs-admin-list-notification', |
||
51 | 'item' => 'rs-admin-item-notification rs-admin-item-note', |
||
52 | 'title' => 'rs-admin-title-notification', |
||
53 | 'link' => 'rs-admin-link-notification', |
||
54 | 'text' => 'rs-admin-text-notification', |
||
55 | 'note' => |
||
56 | [ |
||
57 | 'success' => 'rs-admin-is-success', |
||
58 | 'warning' => 'rs-admin-is-warning', |
||
59 | 'error' => 'rs-admin-is-error', |
||
60 | 'info' => 'rs-admin-is-info' |
||
61 | ] |
||
62 | ] |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * constructor of the class |
||
67 | * |
||
68 | * @since 4.0.0 |
||
69 | * |
||
70 | * @param Language $language instance of the language class |
||
71 | */ |
||
72 | |||
73 | 1 | public function __construct(Language $language) |
|
74 | { |
||
75 | 1 | $this->_language = $language; |
|
76 | 1 | } |
|
77 | |||
78 | /** |
||
79 | * init the class |
||
80 | * |
||
81 | * @since 4.0.0 |
||
82 | * |
||
83 | * @param array $optionArray options of the notification |
||
84 | * |
||
85 | * @return self |
||
86 | */ |
||
87 | |||
88 | 1 | public function init(array $optionArray = []) : self |
|
89 | { |
||
90 | 1 | $this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray); |
|
91 | 1 | $this->_notificationArray = Module\Hook::collect('adminNotification'); |
|
92 | 1 | return $this; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * get the notification array |
||
97 | * |
||
98 | * @since 4.0.0 |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | |||
103 | public function getNotificationArray() : array |
||
104 | { |
||
105 | return $this->_notificationArray; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * render the view |
||
110 | * |
||
111 | * @since 4.0.0 |
||
112 | * |
||
113 | * @return string|null |
||
114 | */ |
||
115 | |||
116 | 1 | public function render() : ?string |
|
117 | { |
||
118 | 1 | $output = null; |
|
119 | 1 | $outputItem = null; |
|
120 | |||
121 | /* html element */ |
||
122 | |||
123 | 1 | $element = new Html\Element(); |
|
124 | $titleElement = $element |
||
125 | 1 | ->copy() |
|
126 | 1 | ->init('h3', |
|
127 | [ |
||
128 | 1 | 'class' => $this->_optionArray['className']['title'] |
|
129 | ]); |
||
130 | $listElement = $element |
||
131 | 1 | ->copy() |
|
132 | 1 | ->init('ul', |
|
133 | [ |
||
134 | 1 | 'class' => $this->_optionArray['className']['list'] |
|
135 | ]); |
||
136 | $itemElement = $element |
||
137 | 1 | ->copy() |
|
138 | 1 | ->init('li', |
|
139 | [ |
||
140 | 1 | 'class' => $this->_optionArray['className']['item'] |
|
141 | ]); |
||
142 | $linkElement = $element |
||
143 | 1 | ->copy() |
|
144 | 1 | ->init('a', |
|
145 | [ |
||
146 | 1 | 'class' => $this->_optionArray['className']['link'] |
|
147 | ]); |
||
148 | $textElement = $element |
||
149 | 1 | ->copy() |
|
150 | 1 | ->init('span', |
|
151 | [ |
||
152 | 1 | 'class' => $this->_optionArray['className']['text'] |
|
153 | ]); |
||
154 | |||
155 | /* process notification */ |
||
156 | |||
157 | 1 | foreach ($this->_notificationArray as $typeKey => $typeValue) |
|
158 | { |
||
159 | 1 | foreach ($typeValue as $notificationKey => $notificationValue) |
|
160 | { |
||
161 | 1 | foreach ($notificationValue as $value) |
|
162 | { |
||
163 | $outputItem .= $itemElement |
||
164 | 1 | ->copy() |
|
165 | 1 | ->addClass($this->_optionArray['className']['note'][$typeKey]) |
|
166 | 1 | ->html( |
|
167 | 1 | $titleElement->text($notificationKey) |
|
168 | ) |
||
169 | 1 | ->append( |
|
170 | 1 | is_array($value) && array_key_exists('text', $value) && array_key_exists('attr', $value) ? |
|
171 | 1 | $linkElement->attr($value['attr'])->text($value['text']) : |
|
172 | 1 | $textElement->text($value) |
|
173 | ); |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | 1 | if ($outputItem) |
|
0 ignored issues
–
show
|
|||
178 | { |
||
179 | 1 | $output .= $listElement->html($outputItem); |
|
180 | } |
||
181 | 1 | return $output; |
|
182 | } |
||
183 | } |
||
184 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: