Completed
Push — master ( 8b01ef...488ec0 )
by Elf
03:30
created

helpers.php ➔ gravatar()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 8
nop 4
dl 0
loc 20
ccs 0
cts 10
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
use Ramsey\Uuid\Uuid;
4
5
if (! function_exists('revision')) {
6
    /**
7
     * Get the revisioned asset path.
8
     *
9
     * @param  string  $path
10
     * @return string
11
     */
12
    function revision($path)
13
    {
14
        if ($rev = array_get(config('assets-version'), trim($path, '/'))) {
15
            return $path.'?'.$rev;
16
        }
17
18
        return $path;
19
    }
20
}
21
22
if (! function_exists('random_uuid')) {
23
    /**
24
     * Generate a version 4 (random) UUID.
25
     *
26
     * @param  bool  $hex
27
     * @return string
28
     */
29
    function random_uuid($hex = false)
30
    {
31
        $uuid = Uuid::uuid4();
32
33
        return $hex ? $uuid->getHex() : $uuid->toString();
34
    }
35
}
36
37
if (! function_exists('is_app')) {
38
    /**
39
     * Determine the current sub application.
40
     *
41
     * @param  string  $identifier
42
     * @return bool
43
     */
44
    function is_app($identifier)
45
    {
46
        return ($appUrl = config('support.url.'.$identifier)) &&
47
            starts_with(
48
                preg_replace('#^https?://#', '', app('request')->url()),
49
                preg_replace('#^https?://#', '', $appUrl)
50
            );
51
    }
52
}
53
54
if (! function_exists('app_url')) {
55
    /**
56
     * Generate an absolute URL to the given path.
57
     *
58
     * @param  string  $path
59
     * @param  mixed  $query
60
     * @param  string  $identifier
61
     * @return string
62
     */
63
    function app_url($path = '', $query = [], $identifier = '')
64
    {
65
        $path = trim($path, '/');
66
        if (! empty($path)) {
67
            $path = '/'.$path;
68
        }
69
70
        if ($query) {
71
            $query = http_build_query($query);
72
            if (! empty($query)) {
73
                $path .= (str_contains($path, ['?', '&', '#']) ? '&' : '?').$query;
74
            }
75
        }
76
77
        $root = $identifier ? config('support.url.'.$identifier) : config('app.url');
78
79
        return $root.$path;
80
    }
81
}
82
83
if (! function_exists('asset_url')) {
84
    /**
85
     * Generate an asset URL to the given path.
86
     *
87
     * @param  string  $path
88
     * @return string
89
     */
90
    function asset_url($path, $identifier = 'asset')
91
    {
92
        return app('url')->assetFrom(
93
            config('support.url.'.$identifier),
94
            revision($path)
95
        );
96
    }
97
}
98
99
if (! function_exists('cdn_url')) {
100
    /**
101
     * Generate an asset CDN URL to the given path.
102
     *
103
     * @param  string  $path
104
     * @return string
105
     */
106
    function cdn_url($path)
107
    {
108
        return asset_url($path, 'cdn');
109
    }
110
}
111