1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Support\HtmlString; |
7
|
|
|
|
8
|
|
|
if (! function_exists('extract_title')) { |
9
|
|
|
/** |
10
|
|
|
* Extract page title from breadcrumbs. |
11
|
|
|
* |
12
|
|
|
* @return string |
13
|
|
|
*/ |
14
|
|
|
function extract_title(HtmlString $breadcrumbs, string $separator = ' » ') |
15
|
|
|
{ |
16
|
|
|
return Str::afterLast(preg_replace('/[\n\r\s]+/', ' ', strip_tags(Str::replaceLast($separator, '', str_replace('</li>', $separator, $breadcrumbs)))), $separator)." {$separator} ".config('app.name'); |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
if (! function_exists('domain')) { |
21
|
|
|
/** |
22
|
|
|
* Return domain host. |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
function domain() |
27
|
|
|
{ |
28
|
|
|
return parse_url(config('app.url'))['host']; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if (! function_exists('intend')) { |
33
|
|
|
/** |
34
|
|
|
* Return redirect response. |
35
|
|
|
* |
36
|
|
|
* @param array $arguments |
37
|
|
|
* @param int $status |
38
|
|
|
* |
39
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
40
|
|
|
*/ |
41
|
|
|
function intend(array $arguments, int $status = 302) |
42
|
|
|
{ |
43
|
|
|
$redirect = redirect(Arr::pull($arguments, 'url'), $status); |
44
|
|
|
|
45
|
|
|
if (request()->expectsJson()) { |
46
|
|
|
$response = collect($arguments['withErrors'] ?? $arguments['with']); |
47
|
|
|
|
48
|
|
|
return response()->json([$response->flatten()->first() ?? 'OK']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
foreach ($arguments as $key => $value) { |
52
|
|
|
$redirect = in_array($key, ['home', 'back']) ? $redirect->{$key}() : $redirect->{$key}($value); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $redirect; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (! function_exists('mimetypes')) { |
60
|
|
|
/** |
61
|
|
|
* Get valid mime types. |
62
|
|
|
* |
63
|
|
|
* @see https://github.com/symfony/http-foundation/blob/3.0/File/MimeType/MimeTypeExtensionGuesser.php |
64
|
|
|
* @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
function mimetypes() |
69
|
|
|
{ |
70
|
|
|
return json_decode(file_get_contents(__DIR__.'/../../resources/data/mimetypes.json'), true); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (! function_exists('timezones')) { |
75
|
|
|
/** |
76
|
|
|
* Get valid timezones. |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
function timezones() |
81
|
|
|
{ |
82
|
|
|
return array_combine(timezone_identifiers_list(), timezone_identifiers_list()); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (! function_exists('timeoffsets')) { |
87
|
|
|
/** |
88
|
|
|
* Get valid time offsets. |
89
|
|
|
* |
90
|
|
|
* @return array |
|
|
|
|
91
|
|
|
*/ |
92
|
|
|
function timeoffsets() |
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
'-1200' => 'UTC -12:00', |
96
|
|
|
'-1100' => 'UTC -11:00', |
97
|
|
|
'-1000' => 'UTC -10:00', |
98
|
|
|
'-0930' => 'UTC -09:30', |
99
|
|
|
'-0900' => 'UTC -09:00', |
100
|
|
|
'-0800' => 'UTC -08:00', |
101
|
|
|
'-0700' => 'UTC -07:00', |
102
|
|
|
'-0600' => 'UTC -06:00', |
103
|
|
|
'-0500' => 'UTC -05:00', |
104
|
|
|
'-0400' => 'UTC -04:00', |
105
|
|
|
'-0330' => 'UTC -03:30', |
106
|
|
|
'-0300' => 'UTC -03:00', |
107
|
|
|
'-0200' => 'UTC -02:00', |
108
|
|
|
'-0100' => 'UTC -01:00', |
109
|
|
|
'+0000' => 'UTC ±00:00', |
110
|
|
|
'+0100' => 'UTC +01:00', |
111
|
|
|
'+0200' => 'UTC +02:00', |
112
|
|
|
'+0300' => 'UTC +03:00', |
113
|
|
|
'+0330' => 'UTC +03:30', |
114
|
|
|
'+0400' => 'UTC +04:00', |
115
|
|
|
'+0430' => 'UTC +04:30', |
116
|
|
|
'+0500' => 'UTC +05:00', |
117
|
|
|
'+0530' => 'UTC +05:30', |
118
|
|
|
'+0545' => 'UTC +05:45', |
119
|
|
|
'+0600' => 'UTC +06:00', |
120
|
|
|
'+0630' => 'UTC +06:30', |
121
|
|
|
'+0700' => 'UTC +07:00', |
122
|
|
|
'+0800' => 'UTC +08:00', |
123
|
|
|
'+0845' => 'UTC +08:45', |
124
|
|
|
'+0900' => 'UTC +09:00', |
125
|
|
|
'+0930' => 'UTC +09:30', |
126
|
|
|
'+1000' => 'UTC +10:00', |
127
|
|
|
'+1030' => 'UTC +10:30', |
128
|
|
|
'+1100' => 'UTC +11:00', |
129
|
|
|
'+1200' => 'UTC +12:00', |
130
|
|
|
'+1245' => 'UTC +12:45', |
131
|
|
|
'+1300' => 'UTC +13:00', |
132
|
|
|
'+1400' => 'UTC +14:00', |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if (! function_exists('array_search_recursive')) { |
138
|
|
|
/** |
139
|
|
|
* Recursively searches the array for a given value and returns the corresponding key if successful. |
140
|
|
|
* |
141
|
|
|
* @param mixed $needle |
142
|
|
|
* @param array $haystack |
143
|
|
|
* |
144
|
|
|
* @return mixed |
|
|
|
|
145
|
|
|
*/ |
146
|
|
|
function array_search_recursive($needle, $haystack) |
147
|
|
|
{ |
148
|
|
|
foreach ($haystack as $key => $value) { |
149
|
|
|
$current_key = $key; |
150
|
|
|
if ($needle === $value || (is_array($value) && array_search_recursive($needle, $value) !== false)) { |
151
|
|
|
return $current_key; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return false; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if (! function_exists('array_trim_recursive')) { |
160
|
|
|
/** |
161
|
|
|
* Recursively trim elements of the given array. |
162
|
|
|
* |
163
|
|
|
* @param mixed $values |
164
|
|
|
* @param string $charlist |
165
|
|
|
* |
166
|
|
|
* @return mixed |
|
|
|
|
167
|
|
|
*/ |
168
|
|
|
function array_trim_recursive($values, $charlist = " \t\n\r\0\x0B") |
169
|
|
|
{ |
170
|
|
|
if (is_array($values)) { |
171
|
|
|
return array_map('array_trim_recursive', $values); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return is_string($values) ? trim($values, $charlist) : $values; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
if (! function_exists('array_filter_recursive')) { |
179
|
|
|
/** |
180
|
|
|
* Recursively filter empty strings and null elements of the given array. |
181
|
|
|
* |
182
|
|
|
* @param array $values |
183
|
|
|
* @param bool $strOnly |
184
|
|
|
* |
185
|
|
|
* @return mixed |
186
|
|
|
*/ |
187
|
|
|
function array_filter_recursive($values, $strOnly = true) |
188
|
|
|
{ |
189
|
|
|
foreach ($values as &$value) { |
190
|
|
|
if (is_array($value)) { |
191
|
|
|
$value = array_filter_recursive($value); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return ! $strOnly ? array_filter($values) : array_filter($values, function ($item) { |
196
|
|
|
return ! is_null($item) && ! ((is_string($item) || is_array($item)) && empty($item)); |
197
|
|
|
}); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.