@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Ffcms\Core\Helper\Type\Any; |
6 | 6 | use Ffcms\Core\Helper\Type\Arr; |
7 | -use Ffcms\Core\Helper\Type\Obj; |
|
8 | 7 | |
9 | 8 | /** |
10 | 9 | * Class SimplePagination. Build and display html pagination block |
@@ -37,17 +37,20 @@ discard block |
||
37 | 37 | public function display(array $property = null): ?string |
38 | 38 | { |
39 | 39 | // total items is less to pagination requirement |
40 | - if (($this->page * $this->step) + 1 > $this->total) |
|
41 | - return null; |
|
40 | + if (($this->page * $this->step) + 1 > $this->total) { |
|
41 | + return null; |
|
42 | + } |
|
42 | 43 | |
43 | 44 | $lastPage = ceil($this->total / $this->step); // 6/5 ~ 2 = 0..2 |
44 | 45 | |
45 | - if ($lastPage <= 1) |
|
46 | - return null; |
|
46 | + if ($lastPage <= 1) { |
|
47 | + return null; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | // prevent hack-boy's any try |
49 | - if ($this->page > $lastPage) |
|
50 | - return null; |
|
51 | + if ($this->page > $lastPage) { |
|
52 | + return null; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | $items = []; |
53 | 56 | // more then 10 items in pagination |
@@ -137,8 +140,9 @@ discard block |
||
137 | 140 | protected function generateItems($start, $end) |
138 | 141 | { |
139 | 142 | // prevent any shit's |
140 | - if ($end <= $start) |
|
141 | - return null; |
|
143 | + if ($end <= $start) { |
|
144 | + return null; |
|
145 | + } |
|
142 | 146 | |
143 | 147 | $items = []; |
144 | 148 | for ($i = $start; $i < $end; $i++) { |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Ffcms\Core\App; |
6 | 6 | use Ffcms\Core\Helper\Type\Any; |
7 | -use Ffcms\Core\Helper\Type\Obj; |
|
8 | 7 | use Ffcms\Core\Helper\Type\Str; |
9 | 8 | use Ffcms\Core\Helper\Url; |
10 | 9 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $purifier = App::$Memory->get('object.purifier.helpers'); |
25 | 25 | } else { |
26 | 26 | $config = \HTMLPurifier_Config::createDefault(); |
27 | - $config->set('Cache.SerializerPath', root . '/Private/Cache/HTMLPurifier/'); |
|
27 | + $config->set('Cache.SerializerPath', root.'/Private/Cache/HTMLPurifier/'); |
|
28 | 28 | $config->set('AutoFormat.AutoParagraph', false); |
29 | 29 | |
30 | 30 | // allow use target=_blank for links |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | $build = null; |
66 | 66 | foreach ($property as $p => $v) { |
67 | 67 | if ($v === null || $v === false || $v === true) { |
68 | - $build .= ' ' . self::nohtml($p); |
|
68 | + $build .= ' '.self::nohtml($p); |
|
69 | 69 | } else { |
70 | - $build .= ' ' . self::nohtml($p) . '="' . self::nohtml($v) . '"'; |
|
70 | + $build .= ' '.self::nohtml($p).'="'.self::nohtml($v).'"'; |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | return $build; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public static function buildSingleTag($tagName, array $property = null, $closeSlash = true) |
84 | 84 | { |
85 | - return '<' . self::nohtml($tagName) . self::applyProperty($property) . ($closeSlash ? '/>' : '>'); |
|
85 | + return '<'.self::nohtml($tagName).self::applyProperty($property).($closeSlash ? '/>' : '>'); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | if ($valueHtml !== true) |
100 | 100 | $value = self::nohtml($value); |
101 | 101 | |
102 | - return '<' . $tagName . self::applyProperty($property) . '>' . $value . '</' . $tagName . '>'; |
|
102 | + return '<'.$tagName.self::applyProperty($property).'>'.$value.'</'.$tagName.'>'; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | if (!Str::contains('/', $elementPoint) || count($elementArray) < 2) { |
141 | 141 | $active = $elementPoint === $currentPoint; |
142 | 142 | } else { |
143 | - $elementPoint = $elementArray[0] . '/' . $elementArray[1]; |
|
143 | + $elementPoint = $elementArray[0].'/'.$elementArray[1]; |
|
144 | 144 | $active = Str::startsWith($elementPoint, $currentPoint); |
145 | 145 | } |
146 | 146 | break; |
147 | 147 | case 'id': |
148 | 148 | $elementArray = explode('/', $elementPoint); |
149 | - $elementPoint = $elementArray[0] . '/' . $elementArray[1]; |
|
149 | + $elementPoint = $elementArray[0].'/'.$elementArray[1]; |
|
150 | 150 | if ($elementArray[2] === null) { // looks like id is not defined in element |
151 | 151 | if (Str::contains('?', $currentPoint)) { |
152 | 152 | $currentPoint = Str::firstIn($currentPoint, '?'); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $currentToId = implode('/', array_slice($currentArray, 0, 3)); |
156 | 156 | $active = $elementPoint === $currentToId; |
157 | 157 | } else { |
158 | - $elementPoint .= '/' . $elementArray[2]; |
|
158 | + $elementPoint .= '/'.$elementArray[2]; |
|
159 | 159 | $active = Str::startsWith($elementPoint, $currentPoint); |
160 | 160 | } |
161 | 161 | break; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public static function convertLink($uri) |
212 | 212 | { |
213 | - $link = App::$Alias->baseUrl . '/'; |
|
213 | + $link = App::$Alias->baseUrl.'/'; |
|
214 | 214 | if (Any::isArray($uri)) { |
215 | 215 | $link .= Url::buildPathway($uri); |
216 | 216 | } elseif (Str::startsWith('http', $uri)) { |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | if (Str::likeEmpty($uri)) |
234 | 234 | return null; |
235 | 235 | |
236 | - return implode('/', array_map(function($v){ |
|
236 | + return implode('/', array_map(function($v) { |
|
237 | 237 | return urlencode($v); |
238 | 238 | }, explode('/', $uri))); |
239 | 239 | } |
@@ -59,8 +59,9 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public static function applyProperty(array $property = null) |
61 | 61 | { |
62 | - if ($property === null || count($property) < 1) |
|
63 | - return null; |
|
62 | + if ($property === null || count($property) < 1) { |
|
63 | + return null; |
|
64 | + } |
|
64 | 65 | |
65 | 66 | $build = null; |
66 | 67 | foreach ($property as $p => $v) { |
@@ -96,8 +97,9 @@ discard block |
||
96 | 97 | public static function buildContainerTag($tagName, array $property = null, $value = null, $valueHtml = false) |
97 | 98 | { |
98 | 99 | $tagName = self::nohtml($tagName); |
99 | - if ($valueHtml !== true) |
|
100 | - $value = self::nohtml($value); |
|
100 | + if ($valueHtml !== true) { |
|
101 | + $value = self::nohtml($value); |
|
102 | + } |
|
101 | 103 | |
102 | 104 | return '<' . $tagName . self::applyProperty($property) . '>' . $value . '</' . $tagName . '>'; |
103 | 105 | } |
@@ -111,8 +113,9 @@ discard block |
||
111 | 113 | public static function safeUri($string, $encode = true) |
112 | 114 | { |
113 | 115 | $string = self::nohtml($string); |
114 | - if ($encode === true) |
|
115 | - $string = self::encode($string); |
|
116 | + if ($encode === true) { |
|
117 | + $string = self::encode($string); |
|
118 | + } |
|
116 | 119 | |
117 | 120 | return $string; |
118 | 121 | } |
@@ -230,8 +233,9 @@ discard block |
||
230 | 233 | */ |
231 | 234 | public static function encode(?string $uri = null) |
232 | 235 | { |
233 | - if (Str::likeEmpty($uri)) |
|
234 | - return null; |
|
236 | + if (Str::likeEmpty($uri)) { |
|
237 | + return null; |
|
238 | + } |
|
235 | 239 | |
236 | 240 | return implode('/', array_map(function($v){ |
237 | 241 | return urlencode($v); |
@@ -7,7 +7,6 @@ |
||
7 | 7 | use Ffcms\Core\Helper\HTML\System\NativeGenerator; |
8 | 8 | use Ffcms\Core\Helper\Type\Any; |
9 | 9 | use Ffcms\Core\Helper\Type\Arr; |
10 | -use Ffcms\Core\Helper\Type\Obj; |
|
11 | 10 | |
12 | 11 | /** |
13 | 12 | * Class Table. Helper for drawing tables using php static call Table::display([params]) |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | // init dom model |
36 | 36 | $dom = new Dom(); |
37 | 37 | // draw response |
38 | - $table = $dom->table(function () use ($dom, $elements, $selectOptions) { |
|
38 | + $table = $dom->table(function() use ($dom, $elements, $selectOptions) { |
|
39 | 39 | $res = null; |
40 | 40 | // check if thead is defined |
41 | 41 | if (isset($elements['thead']) && Any::isArray($elements['thead']) && count($elements['thead']) > 0 && Any::isArray($elements['thead']['titles'])) { |
42 | 42 | // add thead container |
43 | - $res .= $dom->thead(function () use ($dom, $elements, $selectOptions) { |
|
44 | - return $dom->tr(function () use ($dom, $elements, $selectOptions) { |
|
43 | + $res .= $dom->thead(function() use ($dom, $elements, $selectOptions) { |
|
44 | + return $dom->tr(function() use ($dom, $elements, $selectOptions) { |
|
45 | 45 | $tr = null; |
46 | 46 | foreach ($elements['thead']['titles'] as $order => $title) { |
47 | 47 | $th = null; |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | } |
57 | 57 | // make global checkbox for selectable columns |
58 | 58 | if ($selectOptions !== false && $order + 1 === $selectOptions['attachOrder']) { |
59 | - $th = $dom->input(function () { |
|
59 | + $th = $dom->input(function() { |
|
60 | 60 | return null; |
61 | - }, ['type' => 'checkbox', 'name' => 'selectAll']) . ' ' . $th; |
|
61 | + }, ['type' => 'checkbox', 'name' => 'selectAll']).' '.$th; |
|
62 | 62 | } |
63 | 63 | // build tr row collecting all th's |
64 | - $tr .= $dom->th(function () use ($th) { |
|
64 | + $tr .= $dom->th(function() use ($th) { |
|
65 | 65 | return $th; |
66 | 66 | }, $title['property']); |
67 | 67 | } |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | // sort td items inside row by key increment |
81 | 81 | ksort($row); |
82 | 82 | // add data in tr container |
83 | - $tr .= $dom->tr(function () use ($dom, $row, $selectOptions) { |
|
83 | + $tr .= $dom->tr(function() use ($dom, $row, $selectOptions) { |
|
84 | 84 | $td = null; |
85 | 85 | foreach ($row as $order => $item) { |
86 | 86 | if (!Any::isInt($order)) |
87 | 87 | continue; |
88 | 88 | |
89 | 89 | // collect td item |
90 | - $td .= $dom->td(function () use ($dom, $order, $item, $selectOptions) { |
|
90 | + $td .= $dom->td(function() use ($dom, $order, $item, $selectOptions) { |
|
91 | 91 | $text = null; |
92 | 92 | // make text secure based on passed options |
93 | 93 | if ($item['html'] === true) { |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | } |
102 | 102 | // check if selectable box is enabled and equal current order id |
103 | 103 | if ($selectOptions !== false && $order === $selectOptions['attachOrder']) { |
104 | - $text = $dom->input(function (){ |
|
104 | + $text = $dom->input(function() { |
|
105 | 105 | return null; |
106 | - }, Arr::merge($selectOptions['selector'], ['value' => htmlentities($text, null, 'UTF-8')])) . ' ' . $text; |
|
106 | + }, Arr::merge($selectOptions['selector'], ['value' => htmlentities($text, null, 'UTF-8')])).' '.$text; |
|
107 | 107 | } |
108 | 108 | return $text; |
109 | 109 | }, $item['property']); |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | // build js code for "selectAll" checkbox |
127 | 127 | self::buildSelectorHtml($selectOptions); |
128 | 128 | // return response inside "form" tag |
129 | - return $dom->form(function () use ($dom, $selectOptions, $table) { |
|
129 | + return $dom->form(function() use ($dom, $selectOptions, $table) { |
|
130 | 130 | foreach ($selectOptions['buttons'] as $btn) { |
131 | 131 | if (!Any::isArray($btn)) |
132 | 132 | continue; |
133 | 133 | |
134 | - $table .= $dom->input(function(){ |
|
134 | + $table .= $dom->input(function() { |
|
135 | 135 | return null; |
136 | - }, $btn) . ' '; |
|
136 | + }, $btn).' '; |
|
137 | 137 | } |
138 | 138 | return $table; |
139 | 139 | }, $selectOptions['form']); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | private static function buildSelectorHtml(array $opt) |
150 | 150 | { |
151 | 151 | $js = '$(function () { |
152 | - var targetSwitchbox = $(\'input[name="' . $opt['selector']['name'] . '"]\'); |
|
152 | + var targetSwitchbox = $(\'input[name="' . $opt['selector']['name'].'"]\'); |
|
153 | 153 | $(\'input[name="selectAll"]\').change(function() { |
154 | 154 | $(targetSwitchbox).each(function () { |
155 | 155 | $(this).prop(\'checked\', !$(this).is(\':checked\')); |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function display(array $elements): ?string |
25 | 25 | { |
26 | - if (!array_key_exists('tbody', $elements) || !Any::isArray($elements['tbody']['items']) || count($elements['tbody']['items']) < 1) |
|
27 | - return null; |
|
26 | + if (!array_key_exists('tbody', $elements) || !Any::isArray($elements['tbody']['items']) || count($elements['tbody']['items']) < 1) { |
|
27 | + return null; |
|
28 | + } |
|
28 | 29 | |
29 | 30 | $selectOptions = false; |
30 | 31 | if (isset($elements['selectableBox'])) { |
@@ -83,8 +84,9 @@ discard block |
||
83 | 84 | $tr .= $dom->tr(function () use ($dom, $row, $selectOptions) { |
84 | 85 | $td = null; |
85 | 86 | foreach ($row as $order => $item) { |
86 | - if (!Any::isInt($order)) |
|
87 | - continue; |
|
87 | + if (!Any::isInt($order)) { |
|
88 | + continue; |
|
89 | + } |
|
88 | 90 | |
89 | 91 | // collect td item |
90 | 92 | $td .= $dom->td(function () use ($dom, $order, $item, $selectOptions) { |
@@ -128,8 +130,9 @@ discard block |
||
128 | 130 | // return response inside "form" tag |
129 | 131 | return $dom->form(function () use ($dom, $selectOptions, $table) { |
130 | 132 | foreach ($selectOptions['buttons'] as $btn) { |
131 | - if (!Any::isArray($btn)) |
|
132 | - continue; |
|
133 | + if (!Any::isArray($btn)) { |
|
134 | + continue; |
|
135 | + } |
|
133 | 136 | |
134 | 137 | $table .= $dom->input(function(){ |
135 | 138 | return null; |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Ffcms\Core\Helper\Type\Any; |
6 | 6 | use Ffcms\Core\Helper\Type\Arr; |
7 | -use Ffcms\Core\Helper\Type\Obj; |
|
8 | 7 | use Ffcms\Core\Helper\Type\Str; |
9 | 8 | |
10 | 9 | /** |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public static function length_min($object, $length): bool |
25 | 25 | { |
26 | - if (!Any::isLine($object)) |
|
27 | - return false; |
|
26 | + if (!Any::isLine($object)) { |
|
27 | + return false; |
|
28 | + } |
|
28 | 29 | |
29 | 30 | return Str::length((string)$object) >= $length; |
30 | 31 | } |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | */ |
38 | 39 | public static function length_max($object, $length): bool |
39 | 40 | { |
40 | - if (!Any::isLine($object)) |
|
41 | - return false; |
|
41 | + if (!Any::isLine($object)) { |
|
42 | + return false; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | return Str::length((string)$object) <= $length; |
44 | 46 | } |
@@ -51,12 +53,14 @@ discard block |
||
51 | 53 | */ |
52 | 54 | public static function in($object, array $handle): bool |
53 | 55 | { |
54 | - if (!Any::isLine($object)) |
|
55 | - return false; |
|
56 | + if (!Any::isLine($object)) { |
|
57 | + return false; |
|
58 | + } |
|
56 | 59 | |
57 | 60 | // allow empty, validate on required rule |
58 | - if (Any::isEmpty($object)) |
|
59 | - return true; |
|
61 | + if (Any::isEmpty($object)) { |
|
62 | + return true; |
|
63 | + } |
|
60 | 64 | |
61 | 65 | $object = Any::guessValueType($object); |
62 | 66 | |
@@ -81,8 +85,9 @@ discard block |
||
81 | 85 | */ |
82 | 86 | public static function checked($object): bool |
83 | 87 | { |
84 | - if (!Any::isBool($object)) |
|
85 | - return false; |
|
88 | + if (!Any::isBool($object)) { |
|
89 | + return false; |
|
90 | + } |
|
86 | 91 | |
87 | 92 | return (bool)$object; |
88 | 93 | } |
@@ -154,8 +159,9 @@ discard block |
||
154 | 159 | */ |
155 | 160 | public static function email($object): bool |
156 | 161 | { |
157 | - if (!Any::isLine($object)) |
|
158 | - return false; |
|
162 | + if (!Any::isLine($object)) { |
|
163 | + return false; |
|
164 | + } |
|
159 | 165 | |
160 | 166 | // @todo: check this sh@t |
161 | 167 | // allow empty, validate on required rule |
@@ -172,8 +178,9 @@ discard block |
||
172 | 178 | */ |
173 | 179 | public static function phone($object): bool |
174 | 180 | { |
175 | - if (!Any::isLine($object)) |
|
176 | - return false; |
|
181 | + if (!Any::isLine($object)) { |
|
182 | + return false; |
|
183 | + } |
|
177 | 184 | |
178 | 185 | // @todo: check it |
179 | 186 | // allow empty, validate on required rule |
@@ -191,8 +198,9 @@ discard block |
||
191 | 198 | */ |
192 | 199 | public static function url($object): bool |
193 | 200 | { |
194 | - if (!Any::isLine($object)) |
|
195 | - return false; |
|
201 | + if (!Any::isLine($object)) { |
|
202 | + return false; |
|
203 | + } |
|
196 | 204 | |
197 | 205 | // allow empty, validate on required rule |
198 | 206 | //if (Str::likeEmpty($object)) { |
@@ -210,8 +218,9 @@ discard block |
||
210 | 218 | */ |
211 | 219 | public static function equal($object, $value = null): bool |
212 | 220 | { |
213 | - if (!Any::isLine($object)) |
|
214 | - return false; |
|
221 | + if (!Any::isLine($object)) { |
|
222 | + return false; |
|
223 | + } |
|
215 | 224 | |
216 | 225 | return $object === $value; |
217 | 226 | } |
@@ -224,8 +233,9 @@ discard block |
||
224 | 233 | */ |
225 | 234 | public static function notequal($object, $value = null): bool |
226 | 235 | { |
227 | - if (Any::isLine($object)) |
|
228 | - return false; |
|
236 | + if (Any::isLine($object)) { |
|
237 | + return false; |
|
238 | + } |
|
229 | 239 | |
230 | 240 | return $object !== $value; |
231 | 241 | } |
@@ -260,11 +270,13 @@ discard block |
||
260 | 270 | */ |
261 | 271 | public static function reg_match($object, $value): bool |
262 | 272 | { |
263 | - if (!Any::isLine($object)) |
|
264 | - return false; |
|
273 | + if (!Any::isLine($object)) { |
|
274 | + return false; |
|
275 | + } |
|
265 | 276 | |
266 | - if (Str::likeEmpty($object)) |
|
267 | - return true; |
|
277 | + if (Str::likeEmpty($object)) { |
|
278 | + return true; |
|
279 | + } |
|
268 | 280 | |
269 | 281 | // what the f*ck? -> return preg_match($value, $object) > 0; |
270 | 282 | return (bool)preg_match($value, $object); |
@@ -278,8 +290,9 @@ discard block |
||
278 | 290 | */ |
279 | 291 | public static function intList($object, $value): bool |
280 | 292 | { |
281 | - if (!Any::isLine($object)) |
|
282 | - return false; |
|
293 | + if (!Any::isLine($object)) { |
|
294 | + return false; |
|
295 | + } |
|
283 | 296 | |
284 | 297 | return !preg_match('/[^0-9\s,]/$', $object); |
285 | 298 | } |
@@ -293,8 +306,9 @@ discard block |
||
293 | 306 | public static function isFile($object, $value): bool |
294 | 307 | { |
295 | 308 | // allow empty fields, "required" option filter that |
296 | - if ($object === null) |
|
297 | - return true; |
|
309 | + if ($object === null) { |
|
310 | + return true; |
|
311 | + } |
|
298 | 312 | |
299 | 313 | $all = false; |
300 | 314 | // if string is given |
@@ -307,13 +321,15 @@ discard block |
||
307 | 321 | } |
308 | 322 | |
309 | 323 | // input file is not object? |
310 | - if ($object === null || !Any::isObj($object)) |
|
311 | - return false; |
|
324 | + if ($object === null || !Any::isObj($object)) { |
|
325 | + return false; |
|
326 | + } |
|
312 | 327 | |
313 | 328 | // get guess file type, based on mime-type |
314 | 329 | $type = $object->guessExtension(); |
315 | - if ($type === null) |
|
316 | - return false; |
|
330 | + if ($type === null) { |
|
331 | + return false; |
|
332 | + } |
|
317 | 333 | |
318 | 334 | return ($all ? true : Arr::in($type, $value)); |
319 | 335 | } |
@@ -327,21 +343,24 @@ discard block |
||
327 | 343 | public static function sizeFile($object, $value): bool |
328 | 344 | { |
329 | 345 | // allow empty field, validate on filter 'required' |
330 | - if ($object === null) |
|
331 | - return true; |
|
346 | + if ($object === null) { |
|
347 | + return true; |
|
348 | + } |
|
332 | 349 | |
333 | 350 | if (!Any::isArray($value)) { |
334 | 351 | $value = [0, $value]; |
335 | 352 | } |
336 | 353 | |
337 | 354 | // input file is not object? |
338 | - if ($object === null || !Any::isObj($object)) |
|
339 | - return false; |
|
355 | + if ($object === null || !Any::isObj($object)) { |
|
356 | + return false; |
|
357 | + } |
|
340 | 358 | |
341 | 359 | // get file upload size in bytes |
342 | 360 | $realSize = $object->getClientSize(); |
343 | - if ($realSize === null) |
|
344 | - return false; |
|
361 | + if ($realSize === null) { |
|
362 | + return false; |
|
363 | + } |
|
345 | 364 | |
346 | 365 | return $realSize > $value[0] && $realSize <= $value[1]; |
347 | 366 | } |
@@ -5,7 +5,6 @@ |
||
5 | 5 | use Ffcms\Core\App; |
6 | 6 | use Ffcms\Core\Helper\Type\Any; |
7 | 7 | use Ffcms\Core\Helper\Type\Arr; |
8 | -use Ffcms\Core\Helper\Type\Obj; |
|
9 | 8 | use Ffcms\Core\Helper\Type\Str; |
10 | 9 | |
11 | 10 | /** |
@@ -60,8 +60,9 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | $text = strip_tags($html); |
63 | - if ($escapeQuotes) |
|
64 | - $text = $this->escapeQuotes($text); |
|
63 | + if ($escapeQuotes) { |
|
64 | + $text = $this->escapeQuotes($text); |
|
65 | + } |
|
65 | 66 | |
66 | 67 | return $text; |
67 | 68 | } |
@@ -113,8 +114,9 @@ discard block |
||
113 | 114 | */ |
114 | 115 | public static function password_hash($password, $salt = null) |
115 | 116 | { |
116 | - if ($salt === null || !Any::isStr($salt) || Str::length($salt) < 1) |
|
117 | - $salt = App::$Properties->get('passwordSalt'); |
|
117 | + if ($salt === null || !Any::isStr($salt) || Str::length($salt) < 1) { |
|
118 | + $salt = App::$Properties->get('passwordSalt'); |
|
119 | + } |
|
118 | 120 | |
119 | 121 | return crypt($password, $salt); |
120 | 122 | } |
@@ -126,8 +128,9 @@ discard block |
||
126 | 128 | */ |
127 | 129 | public static function simpleHash($string): ?string |
128 | 130 | { |
129 | - if (!Any::isLine($string)) |
|
130 | - return null; |
|
131 | + if (!Any::isLine($string)) { |
|
132 | + return null; |
|
133 | + } |
|
131 | 134 | |
132 | 135 | return dechex(crc32($string)); |
133 | 136 | } |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | |
214 | 214 | /** |
215 | 215 | * Case-ignore replace $needle to $replacement in string $haystack. Alias for function str_ireplace() |
216 | - * @param string|array $needle |
|
217 | - * @param string|array $replacement |
|
216 | + * @param string[] $needle |
|
217 | + * @param string $replacement |
|
218 | 218 | * @param string $haystack |
219 | 219 | * @return string |
220 | 220 | */ |
@@ -318,9 +318,6 @@ discard block |
||
318 | 318 | |
319 | 319 | /** |
320 | 320 | * Concat string with add string by separator |
321 | - * @param string $separator |
|
322 | - * @param string $string1 |
|
323 | - * @param string $string2 |
|
324 | 321 | * @return string |
325 | 322 | */ |
326 | 323 | public static function concat() |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | public static function startsWith(?string $what, ?string $where): bool |
29 | 29 | { |
30 | 30 | // check is not empty string |
31 | - if (self::likeEmpty($what) || self::likeEmpty($where)) |
|
32 | - return false; |
|
31 | + if (self::likeEmpty($what) || self::likeEmpty($where)) { |
|
32 | + return false; |
|
33 | + } |
|
33 | 34 | |
34 | 35 | $prefix = self::sub($where, 0, self::length($what)); |
35 | 36 | return $prefix === $what; |
@@ -44,8 +45,9 @@ discard block |
||
44 | 45 | public static function endsWith(?string $what, ?string $where): bool |
45 | 46 | { |
46 | 47 | // check is not empty string |
47 | - if (self::likeEmpty($what) || self::likeEmpty($where)) |
|
48 | - return false; |
|
48 | + if (self::likeEmpty($what) || self::likeEmpty($where)) { |
|
49 | + return false; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | $suffix = self::sub($where, -self::length($what)); |
51 | 53 | return $suffix === $what; |
@@ -59,8 +61,9 @@ discard block |
||
59 | 61 | */ |
60 | 62 | public static function firstIn(?string $string, ?string $delimiter): ?string |
61 | 63 | { |
62 | - if (self::likeEmpty($string) || self::likeEmpty($delimiter)) |
|
63 | - return null; |
|
64 | + if (self::likeEmpty($string) || self::likeEmpty($delimiter)) { |
|
65 | + return null; |
|
66 | + } |
|
64 | 67 | |
65 | 68 | return strstr($string, $delimiter, true); |
66 | 69 | } |
@@ -74,13 +77,15 @@ discard block |
||
74 | 77 | */ |
75 | 78 | public static function lastIn(?string $string, ?string $delimiter, bool $withoutDelimiter = false): ?string |
76 | 79 | { |
77 | - if (self::likeEmpty($string) || self::likeEmpty($delimiter)) |
|
78 | - return null; |
|
80 | + if (self::likeEmpty($string) || self::likeEmpty($delimiter)) { |
|
81 | + return null; |
|
82 | + } |
|
79 | 83 | |
80 | 84 | $pos = mb_strrpos($string, $delimiter); |
81 | 85 | // if entry is not founded return false |
82 | - if (!Any::isInt($pos)) |
|
83 | - return null; |
|
86 | + if (!Any::isInt($pos)) { |
|
87 | + return null; |
|
88 | + } |
|
84 | 89 | |
85 | 90 | // remove delimiter pointer |
86 | 91 | if ($withoutDelimiter) { |
@@ -98,8 +103,9 @@ discard block |
||
98 | 103 | public static function cleanExtension(?string $string): ?string |
99 | 104 | { |
100 | 105 | // no extension in string is founded |
101 | - if (!self::contains('.', $string)) |
|
102 | - return $string; |
|
106 | + if (!self::contains('.', $string)) { |
|
107 | + return $string; |
|
108 | + } |
|
103 | 109 | |
104 | 110 | $splited = explode('.', $string); |
105 | 111 | array_pop($splited); |
@@ -124,8 +130,9 @@ discard block |
||
124 | 130 | */ |
125 | 131 | public static function lowerCase(?string $string): ?string |
126 | 132 | { |
127 | - if ($string === null) |
|
128 | - return null; |
|
133 | + if ($string === null) { |
|
134 | + return null; |
|
135 | + } |
|
129 | 136 | |
130 | 137 | return mb_strtolower($string, 'UTF-8'); |
131 | 138 | } |
@@ -137,8 +144,9 @@ discard block |
||
137 | 144 | */ |
138 | 145 | public static function upperCase(?string $string = null): ?string |
139 | 146 | { |
140 | - if ($string === null) |
|
141 | - return null; |
|
147 | + if ($string === null) { |
|
148 | + return null; |
|
149 | + } |
|
142 | 150 | |
143 | 151 | return mb_strtoupper($string, 'UTF-8'); |
144 | 152 | } |
@@ -205,8 +213,9 @@ discard block |
||
205 | 213 | */ |
206 | 214 | public static function replace($needle, $replacement, ?string $haystack): ?string |
207 | 215 | { |
208 | - if ($haystack === null) |
|
209 | - return null; |
|
216 | + if ($haystack === null) { |
|
217 | + return null; |
|
218 | + } |
|
210 | 219 | |
211 | 220 | return str_replace($needle, $replacement, $haystack); |
212 | 221 | } |
@@ -220,8 +229,9 @@ discard block |
||
220 | 229 | */ |
221 | 230 | public static function ireplace($needle, $replacement, ?string $haystack): ?string |
222 | 231 | { |
223 | - if ($haystack === null) |
|
224 | - return null; |
|
232 | + if ($haystack === null) { |
|
233 | + return null; |
|
234 | + } |
|
225 | 235 | |
226 | 236 | return str_ireplace($needle, $replacement, $haystack); |
227 | 237 | } |
@@ -9,7 +9,6 @@ |
||
9 | 9 | use Ffcms\Core\Helper\Serialize; |
10 | 10 | use Ffcms\Core\Helper\Type\Any; |
11 | 11 | use Ffcms\Core\Helper\Type\Arr; |
12 | -use Ffcms\Core\Helper\Type\Obj; |
|
13 | 12 | use Ffcms\Core\Helper\Type\Str; |
14 | 13 | |
15 | 14 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | if (Any::isArray($params) && count($params) > 0) { |
56 | 56 | foreach ($params as $var => $value) { |
57 | - $text = Str::replace('%' . $var . '%', $value, $text); |
|
57 | + $text = Str::replace('%'.$var.'%', $value, $text); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | return $text; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function translate(string $text, array $params = null) |
70 | 70 | { |
71 | 71 | $index = null; |
72 | - $namespace = 'Apps\Controller\\' . env_name . '\\'; |
|
72 | + $namespace = 'Apps\Controller\\'.env_name.'\\'; |
|
73 | 73 | foreach (@debug_backtrace() as $caller) { |
74 | 74 | if (isset($caller['class']) && Str::startsWith($namespace, $caller['class'])) { |
75 | 75 | $index = Str::sub((string)$caller['class'], Str::length($namespace)); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | protected function load(string $index): ?array |
87 | 87 | { |
88 | - $file = root . '/I18n/' . env_name . '/' . App::$Request->getLanguage() . '/' . $index . '.php'; |
|
88 | + $file = root.'/I18n/'.env_name.'/'.App::$Request->getLanguage().'/'.$index.'.php'; |
|
89 | 89 | if (!File::exist($file)) |
90 | 90 | return []; |
91 | 91 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function getAvailableLangs(): array |
122 | 122 | { |
123 | 123 | $langs = ['en']; |
124 | - $scan = Directory::scan(root . '/I18n/' . env_name . '/', GLOB_ONLYDIR, true); |
|
124 | + $scan = Directory::scan(root.'/I18n/'.env_name.'/', GLOB_ONLYDIR, true); |
|
125 | 125 | foreach ($scan as $row) { |
126 | 126 | $langs[] = trim($row, '/'); |
127 | 127 | } |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | $this->indexes[] = $index; |
49 | 49 | } |
50 | 50 | |
51 | - if ($this->cached && Any::isStr($text) && isset($this->cached[$text])) |
|
52 | - $text = $this->cached[$text]; |
|
51 | + if ($this->cached && Any::isStr($text) && isset($this->cached[$text])) { |
|
52 | + $text = $this->cached[$text]; |
|
53 | + } |
|
53 | 54 | } |
54 | 55 | |
55 | 56 | if (Any::isArray($params) && count($params) > 0) { |
@@ -86,8 +87,9 @@ discard block |
||
86 | 87 | protected function load(string $index): ?array |
87 | 88 | { |
88 | 89 | $file = root . '/I18n/' . env_name . '/' . App::$Request->getLanguage() . '/' . $index . '.php'; |
89 | - if (!File::exist($file)) |
|
90 | - return []; |
|
90 | + if (!File::exist($file)) { |
|
91 | + return []; |
|
92 | + } |
|
91 | 93 | |
92 | 94 | return require($file); |
93 | 95 | } |
@@ -101,13 +103,15 @@ discard block |
||
101 | 103 | { |
102 | 104 | $path = Normalize::diskFullPath($path); |
103 | 105 | // check if file exist |
104 | - if (!File::exist($path)) |
|
105 | - return false; |
|
106 | + if (!File::exist($path)) { |
|
107 | + return false; |
|
108 | + } |
|
106 | 109 | |
107 | 110 | // load file translations |
108 | 111 | $addTranslation = require($path); |
109 | - if (!Any::isArray($addTranslation)) |
|
110 | - return false; |
|
112 | + if (!Any::isArray($addTranslation)) { |
|
113 | + return false; |
|
114 | + } |
|
111 | 115 | |
112 | 116 | // merge data |
113 | 117 | $this->cached = Arr::merge($this->cached, $addTranslation); |
@@ -142,11 +146,13 @@ discard block |
||
142 | 146 | $lang = App::$Request->getLanguage(); |
143 | 147 | } |
144 | 148 | // unserialize from string to array |
145 | - if (Any::isStr($input)) |
|
146 | - $input = Serialize::decode($input); |
|
149 | + if (Any::isStr($input)) { |
|
150 | + $input = Serialize::decode($input); |
|
151 | + } |
|
147 | 152 | |
148 | - if (Any::isArray($input) && array_key_exists($lang, $input)) |
|
149 | - return $input[$lang]; |
|
153 | + if (Any::isArray($input) && array_key_exists($lang, $input)) { |
|
154 | + return $input[$lang]; |
|
155 | + } |
|
150 | 156 | |
151 | 157 | return $default; |
152 | 158 | } |
@@ -8,7 +8,6 @@ |
||
8 | 8 | use Ffcms\Core\Helper\FileSystem\Directory; |
9 | 9 | use Ffcms\Core\Helper\FileSystem\File; |
10 | 10 | use Ffcms\Core\Helper\Type\Any; |
11 | -use Ffcms\Core\Helper\Type\Obj; |
|
12 | 11 | use Ffcms\Core\Helper\Type\Str; |
13 | 12 | |
14 | 13 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | // check if cache is enabled |
44 | 44 | if (App::$Cache !== null) { |
45 | 45 | // try to get bootable class map from cache, or initialize parsing |
46 | - $cache = App::$Cache->getItem('boot.' . env_name . '.class.map'); |
|
46 | + $cache = App::$Cache->getItem('boot.'.env_name.'.class.map'); |
|
47 | 47 | if (!$cache->isHit()) { |
48 | 48 | $this->compileBootableClasses(); |
49 | 49 | $cache->set($this->objects)->expiresAfter(static::CACHE_TREE_TIME); |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | { |
97 | 97 | // list app root's |
98 | 98 | foreach ($this->appRoots as $app) { |
99 | - $app .= '/Apps/Controller/' . env_name; |
|
99 | + $app .= '/Apps/Controller/'.env_name; |
|
100 | 100 | $files = File::listFiles($app, ['.php'], true); |
101 | 101 | foreach ($files as $file) { |
102 | 102 | // define full class name with namespace |
103 | - $class = 'Apps\Controller\\' . env_name . '\\' . Str::cleanExtension($file); |
|
103 | + $class = 'Apps\Controller\\'.env_name.'\\'.Str::cleanExtension($file); |
|
104 | 104 | // check if class exists (must be loaded over autoloader), boot method exist and this is controller instanceof |
105 | 105 | if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\Core\Arch\Controller', true)) { |
106 | 106 | $this->objects[] = $class; |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | |
111 | 111 | // list widget root's |
112 | 112 | foreach ($this->widgetRoots as $widget) { |
113 | - $widget .= '/Widgets/' . env_name; |
|
113 | + $widget .= '/Widgets/'.env_name; |
|
114 | 114 | // widgets are packed in directory, classname should be the same with root directory name |
115 | 115 | $dirs = Directory::scan($widget, GLOB_ONLYDIR, true); |
116 | 116 | if (!Any::isArray($dirs)) |
117 | 117 | continue; |
118 | 118 | |
119 | 119 | foreach ($dirs as $instance) { |
120 | - $class = 'Widgets\\' . env_name . '\\' . $instance . '\\' . $instance; |
|
120 | + $class = 'Widgets\\'.env_name.'\\'.$instance.'\\'.$instance; |
|
121 | 121 | if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\Core\Arch\Widget', true)) { |
122 | 122 | $this->objects[] = $class; |
123 | 123 | } |
@@ -81,11 +81,13 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | // set default root path if not found anything else |
84 | - if (count($this->appRoots) < 1) |
|
85 | - $this->appRoots = [root]; |
|
84 | + if (count($this->appRoots) < 1) { |
|
85 | + $this->appRoots = [root]; |
|
86 | + } |
|
86 | 87 | |
87 | - if (count($this->widgetRoots) < 1) |
|
88 | - $this->widgetRoots = [root]; |
|
88 | + if (count($this->widgetRoots) < 1) { |
|
89 | + $this->widgetRoots = [root]; |
|
90 | + } |
|
89 | 91 | } |
90 | 92 | |
91 | 93 | /** |
@@ -113,8 +115,9 @@ discard block |
||
113 | 115 | $widget .= '/Widgets/' . env_name; |
114 | 116 | // widgets are packed in directory, classname should be the same with root directory name |
115 | 117 | $dirs = Directory::scan($widget, GLOB_ONLYDIR, true); |
116 | - if (!Any::isArray($dirs)) |
|
117 | - continue; |
|
118 | + if (!Any::isArray($dirs)) { |
|
119 | + continue; |
|
120 | + } |
|
118 | 121 | |
119 | 122 | foreach ($dirs as $instance) { |
120 | 123 | $class = 'Widgets\\' . env_name . '\\' . $instance . '\\' . $instance; |
@@ -133,8 +136,9 @@ discard block |
||
133 | 136 | { |
134 | 137 | $this->startMeasure(__METHOD__); |
135 | 138 | |
136 | - if (!Any::isArray($this->objects)) |
|
137 | - return false; |
|
139 | + if (!Any::isArray($this->objects)) { |
|
140 | + return false; |
|
141 | + } |
|
138 | 142 | |
139 | 143 | foreach ($this->objects as $class) { |
140 | 144 | forward_static_call([$class, 'boot']); |
@@ -3,7 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use Ffcms\Core\App; |
5 | 5 | use Ffcms\Core\Helper\Type\Any; |
6 | -use Ffcms\Core\Helper\Type\Obj; |
|
7 | 6 | |
8 | 7 | /** |
9 | 8 | * Class EventManager. Control and run events. |
@@ -33,8 +33,9 @@ discard block |
||
33 | 33 | public function on($event, \Closure $callback): void |
34 | 34 | { |
35 | 35 | // check if event is a single string and parse it to array single item |
36 | - if (!Any::isArray($event)) |
|
37 | - $event = [$event]; |
|
36 | + if (!Any::isArray($event)) { |
|
37 | + $event = [$event]; |
|
38 | + } |
|
38 | 39 | |
39 | 40 | foreach ($event as $item) { |
40 | 41 | $this->events[$item][] = $callback; |
@@ -50,13 +51,15 @@ discard block |
||
50 | 51 | public function listen($event, \Closure $callback) |
51 | 52 | { |
52 | 53 | // check if $event is a single string and set it as array with one item |
53 | - if (!Any::isArray($event)) |
|
54 | - $event = [$event]; |
|
54 | + if (!Any::isArray($event)) { |
|
55 | + $event = [$event]; |
|
56 | + } |
|
55 | 57 | |
56 | 58 | // each every one event in array |
57 | 59 | foreach ($event as $item) { |
58 | - if (Any::isArray($this->runned) && array_key_exists($item, $this->runned)) |
|
59 | - return call_user_func_array($callback, $this->runned[$item]); |
|
60 | + if (Any::isArray($this->runned) && array_key_exists($item, $this->runned)) { |
|
61 | + return call_user_func_array($callback, $this->runned[$item]); |
|
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | 65 | return false; |
@@ -71,8 +74,9 @@ discard block |
||
71 | 74 | // dynamicly parse input params |
72 | 75 | $args = func_get_args(); |
73 | 76 | |
74 | - if (count($args) < 1) |
|
75 | - return false; |
|
77 | + if (count($args) < 1) { |
|
78 | + return false; |
|
79 | + } |
|
76 | 80 | |
77 | 81 | // get event name |
78 | 82 | $eventName = array_shift($args); |