Completed
Push — master ( 5c06ae...c9967d )
by Elf
02:12
created

helpers.php ➔ fetch_content()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 4
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
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_object($value)) {
56 1
            if (method_exists($value, '__toString')) {
57 1
                return (string) $value;
58
            }
59
60 1
            if (method_exists($value, 'toArray')) {
61 1
                $value = $value->toArray();
62 1
            }
63 1
        }
64
65 1
        return is_string($value) ? $value : json_encode($value, $jsonOptions | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
66
    }
67
}
68
69
if (! function_exists('request')) {
70
    /**
71
     * Get an instance of the current request or an input item from the request.
72
     *
73
     * @param  array|string  $key
74
     * @param  mixed   $default
75
     * @return \Illuminate\Http\Request|string|array
76
     */
77
    function request($key = null, $default = null)
78
    {
79
        if (is_null($key)) {
80
            return app('request');
81
        }
82
83
        if (is_array($key)) {
84
            return app('request')->only($key);
85
        }
86
87
        return data_get(app('request')->all(), $key, $default);
88
    }
89
}
90
91
if (! function_exists('active')) {
92
    /**
93
     * Returns string 'active' if the current request URI matches the given patterns.
94
     *
95
     * @return string
96
     */
97
    function active()
98
    {
99
        return call_user_func_array([app('request'), 'is'], func_get_args()) ? 'active' : '';
100
    }
101
}
102