Completed
Push — master ( eb6e2f...2ffbee )
by recca
04:40
created

ElfinderServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 88
ccs 0
cts 40
cp 0
rs 10
wmc 6
lcom 1
cbo 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handlePublishes() 0 14 1
A boot() 0 10 2
A handleRoutes() 0 10 2
A register() 0 22 1
1
<?php
2
3
namespace Recca0120\Elfinder;
4
5
use elFinder;
6
use Illuminate\Support\Arr;
7
use Illuminate\Routing\Router;
8
use Illuminate\Support\ServiceProvider;
9
10
class ElfinderServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * namespace.
14
     *
15
     * @var string
16
     */
17
    protected $namespace = 'Recca0120\Elfinder\Http\Controllers';
18
19
    /**
20
     * handle routes.
21
     *
22
     * @param \Illuminate\Routing\Router $router
23
     */
24
    public function boot(Router $router)
25
    {
26
        $config = $this->app['config']['elfinder'];
27
        $this->handleRoutes($router, $config);
28
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'elfinder');
29
30
        if ($this->app->runningInConsole() === true) {
31
            $this->handlePublishes();
32
        }
33
    }
34
35
    /**
36
     * Register any application services.
37
     */
38
    public function register()
39
    {
40
        $this->mergeConfigFrom(__DIR__.'/../config/elfinder.php', 'elfinder');
41
42
        $this->app->singleton('elfinder.options', function ($app) {
43
            return new Options(
44
                $app['request'],
45
                $app['files'],
46
                $app['url'],
47
                new LaravelSession($app['session']),
48
                $app['config']['elfinder']
49
            );
50
        });
51
52
        $this->app->singleton('elfinder', function ($app) {
53
            return new elFinder((array) $app['elfinder.options']);
54
        });
55
56
        $this->app->singleton(Connector::class, function ($app) {
57
            return new Connector($app['elfinder']);
58
        });
59
    }
60
61
    /**
62
     * register routes.
63
     *
64
     * @param \Illuminate\Routing\Router $router
65
     * @param array $config
66
     */
67
    protected function handleRoutes(Router $router, $config)
68
    {
69
        if ($this->app->routesAreCached() === false) {
70
            $router->group(array_merge([
71
                'namespace' => $this->namespace,
72
            ], Arr::get($config, 'route', [])), function () {
73
                require __DIR__.'/Http/routes.php';
74
            });
75
        }
76
    }
77
78
    /**
79
     * handle publishes.
80
     *
81
     * @return void
82
     */
83
    protected function handlePublishes()
84
    {
85
        $this->publishes([
86
            __DIR__.'/../resources/views' => base_path('resources/views/vendor/elfinder'),
87
        ], 'views');
88
89
        $this->publishes([
90
            __DIR__.'/../resources/elfinder' => public_path('vendor/elfinder'),
91
        ], 'public');
92
93
        $this->publishes([
94
            __DIR__.'/../config/elfinder.php' => config_path('elfinder.php'),
95
        ], 'config');
96
    }
97
}
98