1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (! function_exists('urlsafe_base64_encode')) { |
4
|
|
|
/** |
5
|
|
|
* Encodes the given data with base64, and returns an URL-safe string. |
6
|
|
|
* |
7
|
|
|
* @param string $data |
8
|
|
|
* @return string |
9
|
|
|
*/ |
10
|
|
|
function urlsafe_base64_encode($data) |
11
|
|
|
{ |
12
|
1 |
|
return strtr(base64_encode($data), ['+' => '-', '/' => '_', '=' => '']); |
13
|
|
|
} |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
if (! function_exists('urlsafe_base64_decode')) { |
17
|
|
|
/** |
18
|
|
|
* Decodes a base64 encoded data. |
19
|
|
|
* |
20
|
|
|
* @param string $data |
21
|
|
|
* @param bool $strict |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
function urlsafe_base64_decode($data, $strict = false) |
25
|
|
|
{ |
26
|
1 |
|
return base64_decode(strtr($data.str_repeat('=', (4 - strlen($data) % 4)), '-_', '+/'), $strict); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if (! function_exists('mb_trim')) { |
31
|
|
|
/** |
32
|
|
|
* Strip whitespace (or other characters) from the beginning and end of a string. |
33
|
|
|
* |
34
|
|
|
* @see https://github.com/vanderlee/PHP-multibyte-functions/blob/master/functions/mb_trim.php |
35
|
|
|
* |
36
|
|
|
* @param string $string |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
function mb_trim($string) |
40
|
|
|
{ |
41
|
1 |
|
return mb_ereg_replace('^\s*([\s\S]*?)\s*$', '\1', $string); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (! function_exists('string_value')) { |
46
|
|
|
/** |
47
|
|
|
* Converts any type to a string. |
48
|
|
|
* |
49
|
|
|
* @param mixed $value |
50
|
|
|
* @param int $jsonOptions JSON_PRETTY_PRINT, etc |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
function string_value($value, $jsonOptions = 0) |
54
|
|
|
{ |
55
|
1 |
|
if (is_string($value)) { |
56
|
|
|
return $value; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
if (method_exists($value, '__toString')) { |
60
|
1 |
|
return (string) $value; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
if (method_exists($value, 'toArray')) { |
64
|
1 |
|
$value = $value->toArray(); |
65
|
1 |
|
} |
66
|
|
|
|
67
|
1 |
|
$jsonOptions |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES; |
68
|
|
|
|
69
|
1 |
|
return json_encode($value, $jsonOptions); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (! function_exists('in_arrayi')) { |
74
|
|
|
/** |
75
|
|
|
* Case-insensitive `in_array`. |
76
|
|
|
* |
77
|
|
|
* @see https://stackoverflow.com/a/2166524/521946 |
78
|
|
|
* @see http://uk.php.net/manual/en/function.in-array.php#89256 |
79
|
|
|
* |
80
|
|
|
* @param string $needle |
81
|
|
|
* @param array $haystack |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
function in_arrayi($needle, $haystack) |
85
|
|
|
{ |
86
|
|
|
return in_array(strtolower($needle), array_map('strtolower', $haystack)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (! function_exists('request')) { |
91
|
|
|
/** |
92
|
|
|
* Get an instance of the current request or an input item from the request. |
93
|
|
|
* |
94
|
|
|
* @param array|string $key |
95
|
|
|
* @param mixed $default |
96
|
|
|
* @return \Illuminate\Http\Request|string|array |
97
|
|
|
*/ |
98
|
|
|
function request($key = null, $default = null) |
99
|
|
|
{ |
100
|
|
|
if (is_null($key)) { |
101
|
|
|
return app('request'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if (is_array($key)) { |
105
|
|
|
return app('request')->only($key); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return data_get(app('request')->all(), $key, $default); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if (! function_exists('active')) { |
113
|
|
|
/** |
114
|
|
|
* Returns string 'active' if the current request URI matches the given patterns. |
115
|
|
|
* |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
function active() |
119
|
|
|
{ |
120
|
|
|
return call_user_func_array([app('request'), 'is'], func_get_args()) ? 'active' : ''; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if (! function_exists('asset_from')) { |
125
|
|
|
/** |
126
|
|
|
* Generate the URL to an asset from a custom root domain such as CDN, etc. |
127
|
|
|
* |
128
|
|
|
* @param string $root |
129
|
|
|
* @param string $path |
130
|
|
|
* @param bool|null $secure |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
function asset_from($root, $path = '', $secure = null) |
134
|
|
|
{ |
135
|
|
|
return app('url')->assetFrom($root, $path, $secure); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|