Completed
Push — master ( e6bfbd...af89b1 )
by recca
03:06
created

ElfinderServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 34.88%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
dl 0
loc 88
ccs 15
cts 43
cp 0.3488
rs 10
c 4
b 0
f 0
wmc 6
lcom 1
cbo 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 2
A register() 0 22 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
                new LaravelSession($app['session']),
48 1
                $app['config']['elfinder']
49 1
            );
50 1
        });
51
52
        $this->app->singleton('elfinder', function ($app) {
53 1
            return new elFinder((array) $app['elfinder.options']);
54 1
        });
55
56
        $this->app->singleton(Connector::class, function ($app) {
57 1
            return new Connector($app['elfinder']);
58 1
        });
59 1
    }
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