Completed
Push — master ( 8a7a4b...43c636 )
by wen
08:31
created

AdminServiceProvider::publishAdmin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Sco\Admin\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Zizaco\Entrust\EntrustServiceProvider;
7
8
/**
9
 *
10
 */
11
class AdminServiceProvider extends ServiceProvider
12
{
13
    protected $commands = [
14
        \Sco\Admin\Commands\Install::class,
15
    ];
16
17
    protected $middlewares = [
18
        'auth.admin'  => \Sco\Admin\Middleware\AdminAuthenticate::class,
19
        'guest.admin' => \Sco\Admin\Middleware\RedirectIfAuthenticated::class,
20
        'admin.menu'     => \Sco\Admin\Middleware\AdminMenu::class,
21
    ];
22
23
    public function getBasePath()
24
    {
25
        return dirname(dirname(__DIR__));
26
    }
27
28
    /**
29
     * Bootstrap the application services.
30
     *
31
     * @return void
32
     */
33
    public function boot()
34
    {
35
        $this->registerMiddleware();
36
37
        // 后台模板目录
38
        $this->loadViewsFrom($this->getBasePath() . '/resources/admin', 'admin');
39
        // 后台语言包目录
40
        $this->loadTranslationsFrom($this->getBasePath() . '/resources/lang', 'Admin');
41
42
        if ($this->app->runningInConsole()) {
0 ignored issues
show
Bug introduced by
The method runningInConsole() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
            $this->loadMigrationsFrom($this->getBasePath() . '/database/migrations');
44
            $this->publishAdmin();
45
        }
46
    }
47
48
    /**
49
     * Register the application services.
50
     *
51
     * @return void
52
     */
53
    public function register()
54
    {
55
        $this->app->register(RouteServiceProvider::class);
56
57
        //$this->commands($this->commands);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
59
        $this->mergeConfigFrom($this->getBasePath() . '/config/admin.php', 'admin');
60
    }
61
62
    protected function registerMiddleware()
63
    {
64
        $router = $this->app['router'];
65
        foreach ($this->middlewares as $key => $middleware) {
66
            $router->middleware($key, $middleware);
67
        }
68
    }
69
70
    protected function publishAdmin()
71
    {
72
        $this->publishConfig();
73
        $this->publishViews();
74
        $this->publishTranslations();
75
    }
76
77
    protected function publishConfig()
78
    {
79
        $this->publishs([
0 ignored issues
show
Bug introduced by
The method publishs() does not exist on Sco\Admin\Providers\AdminServiceProvider. Did you maybe mean publishes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
80
            $this->getBasePath() . '/config/admin.php' => config_path('admin.php'),
81
            $this->getBasePath() . '/config/entrust.php'  => config_path('entrust.php'),
82
        ], 'config');
83
    }
84
85
    protected function publishViews()
86
    {
87
        $this->publishs([
0 ignored issues
show
Bug introduced by
The method publishs() does not exist on Sco\Admin\Providers\AdminServiceProvider. Did you maybe mean publishes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
88
            $this->getBasePath() . '/resources/views' => base_path('resources/views/vendor/admin'),
89
        ], 'views');
90
    }
91
92
    protected function publishTranslations()
93
    {
94
        $this->publishs([
0 ignored issues
show
Bug introduced by
The method publishs() does not exist on Sco\Admin\Providers\AdminServiceProvider. Did you maybe mean publishes()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
95
            $this->getBasePath() . '/resources/lang' => base_path('resources/lang/vendor/admin'),
96
        ], 'lang');
97
    }
98
}
99