Completed
Push — master ( 2ffbee...6662a0 )
by recca
03:16
created

ElfinderServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 36.36%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 89
ccs 16
cts 44
cp 0.3636
rs 10
wmc 6
lcom 1
cbo 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 2
A register() 0 23 1
A handleRoutes() 0 10 2
A handlePublishes() 0 14 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 1
    public function register()
39
    {
40 1
        $this->mergeConfigFrom(__DIR__.'/../config/elfinder.php', 'elfinder');
41
42
        $this->app->singleton('elfinder.options', function ($app) {
43 1
            return (new Options(
44 1
                $app['request'],
45 1
                $app['files'],
46 1
                $app['url'],
47 1
                array_merge($app['config']['elfinder'], [
48 1
                    'session' => new LaravelSession($app['session'])
49 1
                ])
50 1
            ));
51 1
        });
52
53
        $this->app->singleton('elfinder', function ($app) {
54 1
            return new elFinder((array) $app['elfinder.options']);
55 1
        });
56
57
        $this->app->singleton(Connector::class, function ($app) {
58 1
            return new Connector($app['elfinder']);
59 1
        });
60 1
    }
61
62
    /**
63
     * register routes.
64
     *
65
     * @param \Illuminate\Routing\Router $router
66
     * @param array $config
67
     */
68
    protected function handleRoutes(Router $router, $config)
69
    {
70
        if ($this->app->routesAreCached() === false) {
71
            $router->group(array_merge([
72
                'namespace' => $this->namespace,
73
            ], Arr::get($config, 'route', [])), function () {
74
                require __DIR__.'/Http/routes.php';
75
            });
76
        }
77
    }
78
79
    /**
80
     * handle publishes.
81
     *
82
     * @return void
83
     */
84
    protected function handlePublishes()
85
    {
86
        $this->publishes([
87
            __DIR__.'/../resources/views' => base_path('resources/views/vendor/elfinder'),
88
        ], 'views');
89
90
        $this->publishes([
91
            __DIR__.'/../resources/elfinder' => public_path('vendor/elfinder'),
92
        ], 'public');
93
94
        $this->publishes([
95
            __DIR__.'/../config/elfinder.php' => config_path('elfinder.php'),
96
        ], 'config');
97
    }
98
}
99