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__.'/../routes/web.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
|
|
|
|