helpers.php ➔ e()   A
last analyzed

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 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
use Illuminate\Contracts\Routing\UrlGenerator;
12
13
if (!function_exists('assetver')) {
14
    /**
15
     * Get the path to a versioned Elixir file.
16
     *
17
     * @param  string $file
18
     * @return string
19
     *
20
     * @throws \RuntimeException
21
     * @throws \ErrorException
22
     */
23
    function assetver($file)
24
    {
25
        if (!app()->environment('production')) {
26
            return asset($file);
27
        }
28
29
        $file = preg_replace('#^build\/#', '', $file);
30
31
        static $manifest = null;
32
33
        if ($manifest === null) {
34
            try {
35
                $content = file_get_contents(public_path('build/rev/rev-manifest.json'));
36
            } catch (ErrorException $e) {
37
                throw new ErrorException('rev-manifest.json file not found!');
38
            }
39
40
            $manifest = json_decode($content, true);
41
        }
42
43
        if (isset($manifest[$file])) {
44
            return asset('build/rev/' . $manifest[$file]);
45
        }
46
47
        throw new RuntimeException("File {$file} not defined in asset manifest.");
48
    }
49
}
50
51
if (!function_exists('site_url')) {
52
    /**
53
     * Generate a url for the application.
54
     *
55
     * @param  string $path
56
     * @param  mixed  $parameters
57
     * @param  bool   $secure
58
     * @return Illuminate\Contracts\Routing\UrlGenerator|string
59
     */
60
    function site_url($path = null, $parameters = [], $secure = null)
61
    {
62
        if (is_null($path)) {
63
            return app(UrlGenerator::class);
64
        }
65
66
        return lang_url($path, $parameters, $secure);
67
    }
68
}
69
70
if (!function_exists('admin_url')) {
71
    /**
72
     * Generate a url for the application.
73
     *
74
     * @param  string $path
75
     * @param  mixed  $parameters
76
     * @param  bool   $secure
77
     * @return Illuminate\Contracts\Routing\UrlGenerator|string
78
     */
79
    function admin_url($path = null, $parameters = [], $secure = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
80
    {
81
        if (is_null($path)) {
82
            return app(UrlGenerator::class);
83
        }
84
85
        $prefix = config('platfourm.admin_prefix', 'admin');
86
        if ($prefix) {
87
            $path = $prefix . '/' . $path;
88
        }
89
90
        return site_url($path, $parameters, $secure);
91
    }
92
}
93
94
if (!function_exists('p')) {
95
    /**
96
     * Generate a url for the application.
97
     *
98
     * @param  mixed $value
99
     */
100
    function p($value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
    {
102
        $debugbar = app('debugbar');
103
        foreach (func_get_args() as $value) {
104
            $debugbar->addMessage($value, 'debug');
105
        }
106
    }
107
}
108
109
if (!function_exists('array_to_subarray')) {
110
    /**
111
     * Generate a url for the application.
112
     *
113
     * @param  array $array
114
     * @return  array
115
     */
116
    function array_to_subarray(array $array)
117
    {
118
        $return = [];
119
        foreach ($array as $k => $v) {
120
            $return[] = [
121
                'id'   => $k,
122
                'name' => $v,
123
            ];
124
        }
125
126
        return $return;
127
    }
128
}
129
130
if (!function_exists('j')) {
131
    function j($value)
132
    {
133
        return json_encode($value, JSON_UNESCAPED_UNICODE);
134
    }
135
}
136
137
if (!function_exists('e')) {
138
    function e($value)
139
    {
140
        return htmlspecialchars($value);
141
    }
142
}
143
144
if (!function_exists('a')) {
145
    function a($value)
146
    {
147
        return e(j($value));
148
    }
149
}
150