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

Bootstrap   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B handle() 0 26 6
A injectFormAssets() 0 7 1
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