1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Support Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Support Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
use Illuminate\Support\Str; |
17
|
|
|
use Illuminate\Http\JsonResponse; |
18
|
|
|
|
19
|
|
|
if (! function_exists('intend')) { |
20
|
|
|
/** |
21
|
|
|
* Return redirect response. |
22
|
|
|
* |
23
|
|
|
* @param array $arguments |
24
|
|
|
* @param string|null $statusCode |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse |
27
|
|
|
*/ |
28
|
|
|
function intend(array $arguments, $statusCode = null) |
29
|
|
|
{ |
30
|
|
|
$redirect = redirect(); |
31
|
|
|
$statusCode = $statusCode ?: isset($arguments['withErrors']) ? 422 : 200; |
32
|
|
|
|
33
|
|
|
if (request()->expectsJson()) { |
34
|
|
|
return new JsonResponse($arguments['withErrors'] ?: $arguments['with'] ?: 'OK', $statusCode); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
foreach ($arguments as $key => $value) { |
38
|
|
|
$redirect = in_array($key, ['home', 'back']) ? $redirect->{$key}() : $redirect->{$key}($value); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $redirect; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (! function_exists('lower_case')) { |
46
|
|
|
/** |
47
|
|
|
* Convert the given string to lower-case. |
48
|
|
|
* |
49
|
|
|
* @param string $value |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
function lower_case($value) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
return Str::lower($value); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (! function_exists('upper_case')) { |
60
|
|
|
/** |
61
|
|
|
* Convert the given string to upper-case. |
62
|
|
|
* |
63
|
|
|
* @param string $value |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
function upper_case($value) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
return Str::upper($value); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (! function_exists('mimetypes')) { |
74
|
|
|
/** |
75
|
|
|
* Get valid mime types. |
76
|
|
|
* |
77
|
|
|
* @see https://github.com/symfony/http-foundation/blob/3.0/File/MimeType/MimeTypeExtensionGuesser.php |
78
|
|
|
* @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types |
79
|
|
|
* |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
function mimetypes() |
83
|
|
|
{ |
84
|
|
|
return json_decode(file_get_contents(__DIR__.'/../../resources/data/mimetypes.json'), true); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (! function_exists('timezones')) { |
89
|
|
|
/** |
90
|
|
|
* Get valid timezones. |
91
|
|
|
* This list is based upon the timezone database version 2016.1. |
92
|
|
|
* |
93
|
|
|
* @see http://php.net/manual/en/timezones.php |
94
|
|
|
* |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
function timezones() |
98
|
|
|
{ |
99
|
|
|
return json_decode(file_get_contents(__DIR__.'/../../resources/data/timezones.json'), true); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (! function_exists('array_search_recursive')) { |
104
|
|
|
/** |
105
|
|
|
* Recursively searches the array for a given value and returns the corresponding key if successful. |
106
|
|
|
* |
107
|
|
|
* @param mixed $needle |
108
|
|
|
* @param array $haystack |
109
|
|
|
* |
110
|
|
|
* @return mixed |
|
|
|
|
111
|
|
|
*/ |
112
|
|
|
function array_search_recursive($needle, $haystack) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
foreach ($haystack as $key => $value) { |
115
|
|
|
$current_key = $key; |
116
|
|
|
if ($needle === $value || (is_array($value) && array_search_recursive($needle, $value) !== false)) { |
117
|
|
|
return $current_key; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return false; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
Learn more about camelCase.