Completed
Push — master ( f5d20a...67119c )
by Elf
04:51
created

helpers.php ➔ asset_from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Contracts\Support\Jsonable;
4
5
if (! function_exists('in_arrayi')) {
6
    /**
7
     * Case insensitive `in_array`.
8
     *
9
     * @see https://secure.php.net/manual/en/function.in-array.php#89256
10
     *
11
     * @param  string  $needle
12
     * @param  array  $haystack
13
     * @return bool
14
     */
15
    function in_arrayi($needle, $haystack)
16
    {
17
        return in_array(strtolower($needle), array_map('strtolower', $haystack));
18
    }
19
}
20
21
if (! function_exists('mb_trim')) {
22
    /**
23
     * Strip whitespace (or other characters) from the beginning and end of a string.
24
     *
25
     * @see https://github.com/vanderlee/PHP-multibyte-functions/blob/master/functions/mb_trim.php
26
     *
27
     * @param  string  $string
28
     * @return string
29
     */
30
    function mb_trim($string)
31
    {
32
        return mb_ereg_replace('^\s*([\s\S]*?)\s*$', '\1', $string);
33
    }
34
}
35
36
if (! function_exists('string_value')) {
37
    /**
38
     * Convert any type to a string.
39
     *
40
     * @param  mixed  $value
41
     * @param  int  $jsonOptions
42
     * @return string
43
     */
44
    function string_value($value, $jsonOptions = 0)
45
    {
46
        $jsonOptions |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
47
48
        if (is_string($value)) {
49
            return $value;
50
        } elseif ($value instanceof Jsonable) {
51
            return $value->toJson($jsonOptions);
52
        } elseif (method_exists($value, 'toArray')) {
53
            $value = $value->toArray();
54
        } elseif ($value instanceof Traversable) {
55
            $value = iterator_to_array($value);
56
        } elseif (method_exists($value, '__toString')) {
57
            return (string) $value;
58
        }
59
60
        return json_encode($value, $jsonOptions);
61
    }
62
}
63
64
if (! function_exists('active')) {
65
    /**
66
     * Return "active" if the current request URI matches the given patterns.
67
     *
68
     * @param  dynamic  $patterns
69
     * @return string
70
     */
71
    function active(...$patterns)
72
    {
73
        return request()->is(...$patterns) ? 'active' : '';
74
    }
75
}
76