Completed
Push — master ( 69a7c6...5199b6 )
by Song
02:55
created

helpers.php ➔ admin_dump()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\MessageBag;
4
5
if (!function_exists('admin_path')) {
6
7
    /**
8
     * Get admin path.
9
     *
10
     * @param string $path
11
     *
12
     * @return string
13
     */
14
    function admin_path($path = '')
15
    {
16
        return ucfirst(config('admin.directory')).($path ? DIRECTORY_SEPARATOR.$path : $path);
17
    }
18
}
19
20
if (!function_exists('admin_url')) {
21
    /**
22
     * Get admin url.
23
     *
24
     * @param string $path
25
     * @param mixed  $parameters
26
     * @param bool   $secure
27
     *
28
     * @return string
29
     */
30
    function admin_url($path = '', $parameters = [], $secure = null)
31
    {
32
        if (\Illuminate\Support\Facades\URL::isValidUrl($path)) {
33
            return $path;
34
        }
35
36
        $secure = $secure ?: (config('admin.https') || config('admin.secure'));
37
38
        return url(admin_base_path($path), $parameters, $secure);
39
    }
40
}
41
42
if (!function_exists('admin_base_path')) {
43
    /**
44
     * Get admin url.
45
     *
46
     * @param string $path
47
     *
48
     * @return string
49
     */
50
    function admin_base_path($path = '')
51
    {
52
        $prefix = '/'.trim(config('admin.route.prefix'), '/');
53
54
        $prefix = ($prefix == '/') ? '' : $prefix;
55
56
        $path = trim($path, '/');
57
58
        if (is_null($path) || strlen($path) == 0) {
59
            return $prefix ?: '/';
60
        }
61
62
        return $prefix.'/'.$path;
63
    }
64
}
65
66 View Code Duplication
if (!function_exists('admin_toastr')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
68
    /**
69
     * Flash a toastr message bag to session.
70
     *
71
     * @param string $message
72
     * @param string $type
73
     * @param array  $options
74
     */
75
    function admin_toastr($message = '', $type = 'success', $options = [])
76
    {
77
        $toastr = new MessageBag(get_defined_vars());
78
79
        session()->flash('toastr', $toastr);
80
    }
81
}
82
83
if (!function_exists('admin_success')) {
84
85
    /**
86
     * Flash a success message bag to session.
87
     *
88
     * @param string $title
89
     * @param string $message
90
     */
91
    function admin_success($title, $message = '')
92
    {
93
        admin_info($title, $message, 'success');
94
    }
95
}
96
97
if (!function_exists('admin_error')) {
98
99
    /**
100
     * Flash a error message bag to session.
101
     *
102
     * @param string $title
103
     * @param string $message
104
     */
105
    function admin_error($title, $message = '')
106
    {
107
        admin_info($title, $message, 'error');
108
    }
109
}
110
111
if (!function_exists('admin_warning')) {
112
113
    /**
114
     * Flash a warning message bag to session.
115
     *
116
     * @param string $title
117
     * @param string $message
118
     */
119
    function admin_warning($title, $message = '')
120
    {
121
        admin_info($title, $message, 'warning');
122
    }
123
}
124
125 View Code Duplication
if (!function_exists('admin_info')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
127
    /**
128
     * Flash a message bag to session.
129
     *
130
     * @param string $title
131
     * @param string $message
132
     * @param string $type
133
     */
134
    function admin_info($title, $message = '', $type = 'info')
135
    {
136
        $message = new MessageBag(get_defined_vars());
137
138
        session()->flash($type, $message);
139
    }
140
}
141
142
if (!function_exists('admin_asset')) {
143
144
    /**
145
     * @param $path
146
     *
147
     * @return string
148
     */
149
    function admin_asset($path)
150
    {
151
        return (config('admin.https') || config('admin.secure')) ? secure_asset($path) : asset($path);
152
    }
153
}
154
155
if (!function_exists('admin_trans')) {
156
157
    /**
158
     * Translate the given message.
159
     *
160
     * @param string $key
161
     * @param array  $replace
162
     * @param string $locale
163
     *
164
     * @return \Illuminate\Contracts\Translation\Translator|string|array|null
165
     */
166
    function admin_trans($key = null, $replace = [], $locale = null)
167
    {
168
        $line = __($key, $replace, $locale);
169
170
        if (!is_string($line)) {
171
            return $key;
172
        }
173
174
        return $line;
175
    }
176
}
177
178
if (!function_exists('array_delete')) {
179
180
    /**
181
     * Delete from array by value.
182
     *
183
     * @param array $array
184
     * @param mixed $value
185
     */
186
    function array_delete(&$array, $value)
187
    {
188
        foreach ($array as $index => $item) {
189
            if ($value == $item) {
190
                unset($array[$index]);
191
            }
192
        }
193
    }
194
}
195
196
if (!function_exists('class_uses_deep')) {
197
198
    /**
199
     * To get ALL traits including those used by parent classes and other traits.
200
     *
201
     * @param $class
202
     * @param bool $autoload
203
     *
204
     * @return array
205
     */
206
    function class_uses_deep($class, $autoload = true)
207
    {
208
        $traits = [];
209
210
        do {
211
            $traits = array_merge(class_uses($class, $autoload), $traits);
212
        } while ($class = get_parent_class($class));
213
214
        foreach ($traits as $trait => $same) {
215
            $traits = array_merge(class_uses($trait, $autoload), $traits);
216
        }
217
218
        return array_unique($traits);
219
    }
220
}
221
222
if (!function_exists('admin_dump')) {
223
224
    /**
225
     * @param $var
226
     * @return string
227
     */
228
    function admin_dump($var)
0 ignored issues
show
Unused Code introduced by
The parameter $var 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...
229
    {
230
        ob_start();
231
232
        dump(...func_get_args());
233
234
        $contents = ob_get_contents();
235
236
        ob_end_clean();
237
238
        return $contents;
239
    }
240
}