|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Traversable; |
|
4
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
|
5
|
|
|
|
|
6
|
|
|
if (! function_exists('in_arrayi')) { |
|
7
|
|
|
/** |
|
8
|
|
|
* Case insensitive `in_array`. |
|
9
|
|
|
* |
|
10
|
|
|
* @see https://secure.php.net/manual/en/function.in-array.php#89256 |
|
11
|
|
|
* |
|
12
|
|
|
* @param string $needle |
|
13
|
|
|
* @param array $haystack |
|
14
|
|
|
* @return bool |
|
15
|
|
|
*/ |
|
16
|
|
|
function in_arrayi($needle, $haystack) |
|
17
|
|
|
{ |
|
18
|
|
|
return in_array(strtolower($needle), array_map('strtolower', $haystack)); |
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
if (! function_exists('mb_trim')) { |
|
23
|
|
|
/** |
|
24
|
|
|
* Strip whitespace (or other characters) from the beginning and end of a string. |
|
25
|
|
|
* |
|
26
|
|
|
* @see https://github.com/vanderlee/PHP-multibyte-functions/blob/master/functions/mb_trim.php |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $string |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
|
|
function mb_trim($string) |
|
32
|
|
|
{ |
|
33
|
|
|
return mb_ereg_replace('^\s*([\s\S]*?)\s*$', '\1', $string); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (! function_exists('string_value')) { |
|
38
|
|
|
/** |
|
39
|
|
|
* Convert any type to a string. |
|
40
|
|
|
* |
|
41
|
|
|
* @param mixed $value |
|
42
|
|
|
* @param int $jsonOptions |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
function string_value($value, $jsonOptions = 0) |
|
46
|
|
|
{ |
|
47
|
|
|
$jsonOptions |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES; |
|
48
|
|
|
|
|
49
|
|
|
if (is_string($value)) { |
|
50
|
|
|
return $value; |
|
51
|
|
|
} elseif ($value instanceof Jsonable) { |
|
52
|
|
|
return $value->toJson($jsonOptions); |
|
53
|
|
|
} elseif (method_exists($value, 'toArray')) { |
|
54
|
|
|
$value = $value->toArray(); |
|
55
|
|
|
} elseif ($value instanceof Traversable) { |
|
56
|
|
|
$value = iterator_to_array($value); |
|
57
|
|
|
} elseif (method_exists($value, '__toString')) { |
|
58
|
|
|
return (string) $value; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return json_encode($value, $jsonOptions); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (! function_exists('active')) { |
|
66
|
|
|
/** |
|
67
|
|
|
* Return "active" if the current request URI matches the given patterns. |
|
68
|
|
|
* |
|
69
|
|
|
* @param dynamic $patterns |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
function active(...$patterns) |
|
73
|
|
|
{ |
|
74
|
|
|
return request()->is(...$patterns) ? 'active' : ''; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (! function_exists('asset_from')) { |
|
79
|
|
|
/** |
|
80
|
|
|
* Generate the URL to an asset from a custom root domain such as CDN, etc. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $root |
|
83
|
|
|
* @param string $path |
|
84
|
|
|
* @param bool|null $secure |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
function asset_from($root, $path = '', $secure = null) |
|
88
|
|
|
{ |
|
89
|
|
|
return app('url')->assetFrom($root, $path, $secure); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|