Completed
Pull Request — master (#4037)
by Muhlis
02:22
created

HasAssets::bootstrapCss()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
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/font-awesome/css/font-awesome.min.css',
65
        'vendor/laravel-admin/laravel-admin/laravel-admin.css',
66
        'vendor/laravel-admin/nprogress/nprogress.css',
67
        'vendor/laravel-admin/sweetalert2/dist/sweetalert2.css',
68
        'vendor/laravel-admin/nestable/nestable.css',
69
        'vendor/laravel-admin/toastr/build/toastr.min.css',
70
        'vendor/laravel-admin/bootstrap3-editable/css/bootstrap-editable.css',
71
        'vendor/laravel-admin/google-fonts/fonts.css',
72
        'vendor/laravel-admin/AdminLTE/dist/css/AdminLTE.min.css',
73
    ];
74
75
    /**
76
     * @var array
77
     */
78
    public static $baseJs = [
79
        'vendor/laravel-admin/AdminLTE/bootstrap/js/bootstrap.min.js',
80
        'vendor/laravel-admin/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js',
81
        'vendor/laravel-admin/AdminLTE/dist/js/app.min.js',
82
        'vendor/laravel-admin/jquery-pjax/jquery.pjax.js',
83
        'vendor/laravel-admin/nprogress/nprogress.js',
84
        'vendor/laravel-admin/nestable/jquery.nestable.js',
85
        'vendor/laravel-admin/toastr/build/toastr.min.js',
86
        'vendor/laravel-admin/bootstrap3-editable/js/bootstrap-editable.min.js',
87
        'vendor/laravel-admin/sweetalert2/dist/sweetalert2.min.js',
88
        'vendor/laravel-admin/laravel-admin/laravel-admin.js',
89
    ];
90
91
    /**
92
     * @var string
93
     */
94
    public static $jQuery = 'vendor/laravel-admin/AdminLTE/plugins/jQuery/jQuery-2.1.4.min.js';
95
96
    /**
97
     * @var string
98
     */
99
    public static $bootstrapCss = 'vendor/laravel-admin/AdminLTE/bootstrap/css/bootstrap.min.css';
100
101
    /**
102
     * @var array
103
     */
104
    public static $minifyIgnores = [];
105
106
    /**
107
     * Add css or get all css.
108
     *
109
     * @param null $css
110
     * @param bool $minify
111
     *
112
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
113
     */
114 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...
115
    {
116
        static::ignoreMinify($css, $minify);
117
118
        if (!is_null($css)) {
119
            return self::$css = array_merge(self::$css, (array) $css);
120
        }
121
122
        if (!$css = static::getMinifiedCss()) {
123
            $css = array_merge(static::$css, static::baseCss());
124
        }
125
126
        $css = array_filter(array_unique($css));
127
128
        return view('admin::partials.css', compact('css'));
129
    }
130
131
    /**
132
     * @param null $css
133
     * @param bool $minify
134
     *
135
     * @return array|null
136
     */
137
    public static function baseCss($css = null, $minify = true)
138
    {
139
        static::ignoreMinify($css, $minify);
140
141
        if (!is_null($css)) {
142
            return static::$baseCss = $css;
143
        }
144
145
        $skin = config('admin.skin', 'skin-blue-light');
146
147
        array_unshift(static::$baseCss, "vendor/laravel-admin/AdminLTE/dist/css/skins/{$skin}.min.css");
148
149
        return static::$baseCss;
150
    }
151
152
    /**
153
     * Add js or get all js.
154
     *
155
     * @param null $js
156
     * @param bool $minify
157
     *
158
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
159
     */
160 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...
161
    {
162
        static::ignoreMinify($js, $minify);
163
164
        if (!is_null($js)) {
165
            return self::$js = array_merge(self::$js, (array) $js);
166
        }
167
168
        if (!$js = static::getMinifiedJs()) {
169
            $js = array_merge(static::baseJs(), static::$js);
170
        }
171
172
        $js = array_filter(array_unique($js));
173
174
        return view('admin::partials.js', compact('js'));
175
    }
176
177
    /**
178
     * Add js or get all js.
179
     *
180
     * @param null $js
181
     *
182
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
183
     */
184
    public static function headerJs($js = null)
185
    {
186
        if (!is_null($js)) {
187
            return self::$headerJs = array_merge(self::$headerJs, (array) $js);
188
        }
189
190
        return view('admin::partials.js', ['js' => array_unique(static::$headerJs)]);
191
    }
192
193
    /**
194
     * @param null $js
195
     * @param bool $minify
196
     *
197
     * @return array|null
198
     */
199
    public static function baseJs($js = null, $minify = true)
200
    {
201
        static::ignoreMinify($js, $minify);
202
203
        if (!is_null($js)) {
204
            return static::$baseJs = $js;
205
        }
206
207
        return static::$baseJs;
208
    }
209
210
    /**
211
     * @param string $assets
212
     * @param bool   $ignore
213
     */
214
    public static function ignoreMinify($assets, $ignore = true)
215
    {
216
        if (!$ignore) {
217
            static::$minifyIgnores[] = $assets;
218
        }
219
    }
220
221
    /**
222
     * @param string $script
223
     * @param bool   $deferred
224
     *
225
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
226
     */
227
    public static function script($script = '', $deferred = false)
228
    {
229
        if (!empty($script)) {
230
            if ($deferred) {
231
                return self::$deferredScript = array_merge(self::$deferredScript, (array) $script);
232
            }
233
234
            return self::$script = array_merge(self::$script, (array) $script);
235
        }
236
237
        $script = array_unique(array_merge(static::$script, static::$deferredScript));
238
239
        return view('admin::partials.script', compact('script'));
240
    }
241
242
    /**
243
     * @param string $style
244
     *
245
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
246
     */
247 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...
248
    {
249
        if (!empty($style)) {
250
            return self::$style = array_merge(self::$style, (array) $style);
251
        }
252
253
        return view('admin::partials.style', ['style' => array_unique(self::$style)]);
254
    }
255
256
    /**
257
     * @param string $html
258
     *
259
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
260
     */
261 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...
262
    {
263
        if (!empty($html)) {
264
            return self::$html = array_merge(self::$html, (array) $html);
265
        }
266
267
        return view('admin::partials.html', ['html' => array_unique(self::$html)]);
268
    }
269
270
    /**
271
     * @param string $key
272
     *
273
     * @return mixed
274
     */
275
    protected static function getManifestData($key)
276
    {
277
        if (!empty(static::$manifestData)) {
278
            return static::$manifestData[$key];
279
        }
280
281
        static::$manifestData = json_decode(
282
            file_get_contents(public_path(static::$manifest)), true
283
        );
284
285
        return static::$manifestData[$key];
286
    }
287
288
    /**
289
     * @return bool|mixed
290
     */
291 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...
292
    {
293
        if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) {
294
            return false;
295
        }
296
297
        return static::getManifestData('css');
298
    }
299
300
    /**
301
     * @return bool|mixed
302
     */
303 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...
304
    {
305
        if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) {
306
            return false;
307
        }
308
309
        return static::getManifestData('js');
310
    }
311
312
    /**
313
     * @return string
314
     */
315
    public function jQuery()
316
    {
317
        return admin_asset(static::$jQuery);
318
    }
319
320
    /**
321
     * @return string
322
     */
323
    public function bootstrapCss()
324
    {
325
        return admin_asset(static::$bootstrapCss);
326
    }
327
}
328