Completed
Push — master ( 3eeff7...ca19a1 )
by Song
02:24
created

Bootstrap::injectFormAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Middleware;
4
5
use Encore\Admin\Admin;
6
use Encore\Admin\Form;
7
use Encore\Admin\Grid;
8
use Illuminate\Http\Request;
9
10
class Bootstrap
11
{
12
    public function handle(Request $request, \Closure $next)
13
    {
14
        Form::registerBuiltinFields();
15
16
        Grid::registerColumnDisplayer();
17
18
        if (file_exists($bootstrap = admin_path('bootstrap.php'))) {
19
            require $bootstrap;
20
        }
21
22
        if (! empty(Admin::$booting)) {
23
            foreach (Admin::$booting as $callable) {
24
                call_user_func($callable);
25
            }
26
        }
27
28
        $this->injectFormAssets();
29
30
        if (! empty(Admin::$booted)) {
31
            foreach (Admin::$booted as $callable) {
32
                call_user_func($callable);
33
            }
34
        }
35
36
        return $next($request);
37
    }
38
39
    /**
40
     * Inject assets of all form fields.
41
     */
42
    protected function injectFormAssets()
43
    {
44
        $assets = Form::collectFieldAssets();
45
46
        Admin::css($assets['css']);
47
        Admin::js($assets['js']);
48
    }
49
}
50