|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
|
|
7
|
|
|
if (! function_exists('domain')) { |
|
8
|
|
|
/** |
|
9
|
|
|
* Return domain host. |
|
10
|
|
|
* |
|
11
|
|
|
* @return string |
|
12
|
|
|
*/ |
|
13
|
|
|
function domain() |
|
14
|
|
|
{ |
|
15
|
|
|
return parse_url(config('app.url'))['host']; |
|
16
|
|
|
} |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
if (! function_exists('intend')) { |
|
20
|
|
|
/** |
|
21
|
|
|
* Return redirect response. |
|
22
|
|
|
* |
|
23
|
|
|
* @param array $arguments |
|
24
|
|
|
* @param int $status |
|
25
|
|
|
* |
|
26
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
27
|
|
|
*/ |
|
28
|
|
|
function intend(array $arguments, int $status = 302) |
|
29
|
|
|
{ |
|
30
|
|
|
$redirect = redirect(array_pull($arguments, 'url'), $status); |
|
31
|
|
|
|
|
32
|
|
|
if (request()->expectsJson()) { |
|
33
|
|
|
$response = collect($arguments['withErrors'] ?? $arguments['with']); |
|
34
|
|
|
|
|
35
|
|
|
return response()->json([$response->flatten()->first() ?? 'OK']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
foreach ($arguments as $key => $value) { |
|
39
|
|
|
$redirect = in_array($key, ['home', 'back']) ? $redirect->{$key}() : $redirect->{$key}($value); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return $redirect; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (! function_exists('lower_case')) { |
|
47
|
|
|
/** |
|
48
|
|
|
* Convert the given string to lower-case. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $value |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
function lower_case($value) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
return Str::lower($value); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if (! function_exists('upper_case')) { |
|
61
|
|
|
/** |
|
62
|
|
|
* Convert the given string to upper-case. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $value |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
function upper_case($value) |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
return Str::upper($value); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (! function_exists('mimetypes')) { |
|
75
|
|
|
/** |
|
76
|
|
|
* Get valid mime types. |
|
77
|
|
|
* |
|
78
|
|
|
* @see https://github.com/symfony/http-foundation/blob/3.0/File/MimeType/MimeTypeExtensionGuesser.php |
|
79
|
|
|
* @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types |
|
80
|
|
|
* |
|
81
|
|
|
* @return array |
|
82
|
|
|
*/ |
|
83
|
|
|
function mimetypes() |
|
84
|
|
|
{ |
|
85
|
|
|
return json_decode(file_get_contents(__DIR__.'/../../resources/data/mimetypes.json'), true); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if (! function_exists('timezones')) { |
|
90
|
|
|
/** |
|
91
|
|
|
* Get valid timezones. |
|
92
|
|
|
* This list is based upon the timezone database version 2017.2. |
|
93
|
|
|
* |
|
94
|
|
|
* @see http://php.net/manual/en/timezones.php |
|
95
|
|
|
* |
|
96
|
|
|
* @return array |
|
97
|
|
|
*/ |
|
98
|
|
|
function timezones() |
|
99
|
|
|
{ |
|
100
|
|
|
return json_decode(file_get_contents(__DIR__.'/../../resources/data/timezones.json'), true); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if (! function_exists('array_search_recursive')) { |
|
105
|
|
|
/** |
|
106
|
|
|
* Recursively searches the array for a given value and returns the corresponding key if successful. |
|
107
|
|
|
* |
|
108
|
|
|
* @param mixed $needle |
|
109
|
|
|
* @param array $haystack |
|
110
|
|
|
* |
|
111
|
|
|
* @return mixed |
|
|
|
|
|
|
112
|
|
|
*/ |
|
113
|
|
|
function array_search_recursive($needle, $haystack) |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
foreach ($haystack as $key => $value) { |
|
116
|
|
|
$current_key = $key; |
|
117
|
|
|
if ($needle === $value || (is_array($value) && array_search_recursive($needle, $value) !== false)) { |
|
118
|
|
|
return $current_key; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return false; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if (! function_exists('array_trim_recursive')) { |
|
127
|
|
|
/** |
|
128
|
|
|
* Recursively trim elements of the given array. |
|
129
|
|
|
* |
|
130
|
|
|
* @param mixed $values |
|
131
|
|
|
* @param string $charlist |
|
132
|
|
|
* |
|
133
|
|
|
* @return mixed |
|
|
|
|
|
|
134
|
|
|
*/ |
|
135
|
|
|
function array_trim_recursive($values, $charlist = " \t\n\r\0\x0B") |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
if (is_array($values)) { |
|
138
|
|
|
return array_map('array_trim_recursive', $values); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return is_string($values) ? trim($values, $charlist) : $values; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if (! function_exists('array_filter_recursive')) { |
|
146
|
|
|
/** |
|
147
|
|
|
* Recursively filter empty strings and null elements of the given array. |
|
148
|
|
|
* |
|
149
|
|
|
* @param array $values |
|
150
|
|
|
* @param bool $strOnly |
|
151
|
|
|
* |
|
152
|
|
|
* @return mixed |
|
153
|
|
|
*/ |
|
154
|
|
|
function array_filter_recursive($values, $strOnly = true) |
|
|
|
|
|
|
155
|
|
|
{ |
|
156
|
|
|
foreach ($values as &$value) { |
|
157
|
|
|
if (is_array($value)) { |
|
158
|
|
|
$value = array_filter_recursive($value); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return ! $strOnly ? array_filter($values) : array_filter($values, function ($item) { |
|
163
|
|
|
return ! is_null($item) && ! ((is_string($item) || is_array($item)) && empty($item)); |
|
164
|
|
|
}); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
Learn more about camelCase.