Completed
Push — master ( 325776...ee487f )
by Song
02:30
created

HasAssets::ignoreMinify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Traits;
4
5
trait HasAssets
6
{
7
    /**
8
     * @var array
9
     */
10
    public static $script = [];
11
12
    /**
13
     * @var array
14
     */
15
    public static $deferredScript = [];
16
17
    /**
18
     * @var array
19
     */
20
    public static $style = [];
21
22
    /**
23
     * @var array
24
     */
25
    public static $css = [];
26
27
    /**
28
     * @var array
29
     */
30
    public static $js = [];
31
32
    /**
33
     * @var array
34
     */
35
    public static $html = [];
36
37
    /**
38
     * @var array
39
     */
40
    public static $headerJs = [];
41
42
    /**
43
     * @var string
44
     */
45
    public static $manifest = 'vendor/laravel-admin/minify-manifest.json';
46
47
    /**
48
     * @var array
49
     */
50
    public static $manifestData = [];
51
52
    /**
53
     * @var array
54
     */
55
    public static $min = [
56
        'js'  => 'vendor/laravel-admin/laravel-admin.min.js',
57
        'css' => 'vendor/laravel-admin/laravel-admin.min.css',
58
    ];
59
60
    /**
61
     * @var array
62
     */
63
    public static $baseCss = [
64
        'vendor/laravel-admin/AdminLTE/bootstrap/css/bootstrap.min.css',
65
        'vendor/laravel-admin/font-awesome/css/font-awesome.min.css',
66
        'vendor/laravel-admin/laravel-admin/laravel-admin.css',
67
        'vendor/laravel-admin/nprogress/nprogress.css',
68
        'vendor/laravel-admin/sweetalert2/dist/sweetalert2.css',
69
        'vendor/laravel-admin/nestable/nestable.css',
70
        'vendor/laravel-admin/toastr/build/toastr.min.css',
71
        'vendor/laravel-admin/bootstrap3-editable/css/bootstrap-editable.css',
72
        'vendor/laravel-admin/google-fonts/fonts.css',
73
        'vendor/laravel-admin/AdminLTE/dist/css/AdminLTE.min.css',
74
    ];
75
76
    /**
77
     * @var array
78
     */
79
    public static $baseJs = [
80
        'vendor/laravel-admin/AdminLTE/bootstrap/js/bootstrap.min.js',
81
        'vendor/laravel-admin/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js',
82
        'vendor/laravel-admin/AdminLTE/dist/js/app.min.js',
83
        'vendor/laravel-admin/jquery-pjax/jquery.pjax.js',
84
        'vendor/laravel-admin/nprogress/nprogress.js',
85
        'vendor/laravel-admin/nestable/jquery.nestable.js',
86
        'vendor/laravel-admin/toastr/build/toastr.min.js',
87
        'vendor/laravel-admin/bootstrap3-editable/js/bootstrap-editable.min.js',
88
        'vendor/laravel-admin/sweetalert2/dist/sweetalert2.min.js',
89
        'vendor/laravel-admin/laravel-admin/laravel-admin.js',
90
    ];
91
92
    /**
93
     * @var string
94
     */
95
    public static $jQuery = 'vendor/laravel-admin/AdminLTE/plugins/jQuery/jQuery-2.1.4.min.js';
96
97
    /**
98
     * @var array
99
     */
100
    public static $minifyIgnores = [];
101
102
    /**
103
     * Add css or get all css.
104
     *
105
     * @param null $css
106
     * @param bool $minify
107
     *
108
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
109
     */
110 View Code Duplication
    public static function css($css = null, $minify = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
111
    {
112
        static::ignoreMinify($css, $minify);
113
114
        if (!is_null($css)) {
115
            return self::$css = array_merge(self::$css, (array) $css);
116
        }
117
118
        if (!$css = static::getMinifiedCss()) {
119
            $css = array_merge(static::$css, static::baseCss());
120
        }
121
122
        $css = array_filter(array_unique($css));
123
124
        return view('admin::partials.css', compact('css'));
125
    }
126
127
    /**
128
     * @param null $css
129
     * @param bool $minify
130
     *
131
     * @return array|null
132
     */
133
    public static function baseCss($css = null, $minify = true)
134
    {
135
        static::ignoreMinify($css, $minify);
136
137
        if (!is_null($css)) {
138
            return static::$baseCss = $css;
139
        }
140
141
        $skin = config('admin.skin', 'skin-blue-light');
142
143
        array_unshift(static::$baseCss, "vendor/laravel-admin/AdminLTE/dist/css/skins/{$skin}.min.css");
144
145
        return static::$baseCss;
146
    }
147
148
    /**
149
     * Add js or get all js.
150
     *
151
     * @param null $js
152
     * @param bool $minify
153
     *
154
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
155
     */
156 View Code Duplication
    public static function js($js = null, $minify = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
157
    {
158
        static::ignoreMinify($js, $minify);
159
160
        if (!is_null($js)) {
161
            return self::$js = array_merge(self::$js, (array) $js);
162
        }
163
164
        if (!$js = static::getMinifiedJs()) {
165
            $js = array_merge(static::baseJs(), static::$js);
166
        }
167
168
        $js = array_filter(array_unique($js));
169
170
        return view('admin::partials.js', compact('js'));
171
    }
172
173
    /**
174
     * Add js or get all js.
175
     *
176
     * @param null $js
177
     *
178
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
179
     */
180
    public static function headerJs($js = null)
181
    {
182
        if (!is_null($js)) {
183
            return self::$headerJs = array_merge(self::$headerJs, (array) $js);
184
        }
185
186
        return view('admin::partials.js', ['js' => array_unique(static::$headerJs)]);
187
    }
188
189
    /**
190
     * @param null $js
191
     * @param bool $minify
192
     *
193
     * @return array|null
194
     */
195
    public static function baseJs($js = null, $minify = true)
196
    {
197
        static::ignoreMinify($js, $minify);
198
199
        if (!is_null($js)) {
200
            return static::$baseJs = $js;
201
        }
202
203
        return static::$baseJs;
204
    }
205
206
    /**
207
     * @param string $assets
208
     *
209
     * @param bool $ignore
210
     */
211
    public static function ignoreMinify($assets, $ignore = true)
212
    {
213
        if (!$ignore) {
214
            static::$minifyIgnores[] = $assets;
215
        }
216
    }
217
218
    /**
219
     * @param string $script
220
     * @param bool   $deferred
221
     *
222
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
223
     */
224
    public static function script($script = '', $deferred = false)
225
    {
226
        if (!empty($script)) {
227
            if ($deferred) {
228
                return self::$deferredScript = array_merge(self::$deferredScript, (array) $script);
229
            }
230
231
            return self::$script = array_merge(self::$script, (array) $script);
232
        }
233
234
        $script = array_unique(array_merge(static::$script, static::$deferredScript));
235
236
        return view('admin::partials.script', compact('script'));
237
    }
238
239
    /**
240
     * @param string $style
241
     *
242
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
243
     */
244 View Code Duplication
    public static function style($style = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
245
    {
246
        if (!empty($style)) {
247
            return self::$style = array_merge(self::$style, (array) $style);
248
        }
249
250
        return view('admin::partials.style', ['style' => array_unique(self::$style)]);
251
    }
252
253
    /**
254
     * @param string $html
255
     *
256
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
257
     */
258 View Code Duplication
    public static function html($html = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
259
    {
260
        if (!empty($html)) {
261
            return self::$html = array_merge(self::$html, (array) $html);
262
        }
263
264
        return view('admin::partials.html', ['html' => array_unique(self::$html)]);
265
    }
266
267
    /**
268
     * @param string $key
269
     *
270
     * @return mixed
271
     */
272
    protected static function getManifestData($key)
273
    {
274
        if (!empty(static::$manifestData)) {
275
            return static::$manifestData[$key];
276
        }
277
278
        static::$manifestData = json_decode(
279
            file_get_contents(public_path(static::$manifest)), true
280
        );
281
282
        return static::$manifestData[$key];
283
    }
284
285
    /**
286
     * @return bool|mixed
287
     */
288 View Code Duplication
    protected static function getMinifiedCss()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
289
    {
290
        if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) {
291
            return false;
292
        }
293
294
        return static::getManifestData('css');
295
    }
296
297
    /**
298
     * @return bool|mixed
299
     */
300 View Code Duplication
    protected static function getMinifiedJs()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
301
    {
302
        if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) {
303
            return false;
304
        }
305
306
        return static::getManifestData('js');
307
    }
308
309
    /**
310
     * @return string
311
     */
312
    public function jQuery()
313
    {
314
        return admin_asset(static::$jQuery);
315
    }
316
}
317