|
1
|
|
|
<?php namespace Modules\Media\Providers; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; |
|
4
|
|
|
use Illuminate\Support\Facades\Validator; |
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use Modules\Media\Console\RefreshThumbnailCommand; |
|
7
|
|
|
use Modules\Media\Entities\File; |
|
8
|
|
|
use Modules\Media\Events\Handlers\HandleMediaStorage; |
|
9
|
|
|
use Modules\Media\Events\Handlers\RemovePolymorphicLink; |
|
10
|
|
|
use Modules\Media\Repositories\Eloquent\EloquentFileRepository; |
|
11
|
|
|
use Modules\Media\Repositories\FileRepository; |
|
12
|
|
|
|
|
13
|
|
|
class MediaServiceProvider extends ServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Indicates if loading of the provider is deferred. |
|
17
|
|
|
* |
|
18
|
|
|
* @var bool |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $defer = false; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Register the service provider. |
|
24
|
|
|
* |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
public function register() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->registerBindings(); |
|
30
|
|
|
|
|
31
|
|
|
$this->registerCommands(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function boot(DispatcherContract $events) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->registerMaxFolderSizeValidator(); |
|
37
|
|
|
|
|
38
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'asgard.media.config'); |
|
39
|
|
|
$this->publishes([__DIR__ . '/../Config/config.php' => config_path('asgard.media.config' . '.php'), ], 'config'); |
|
40
|
|
|
|
|
41
|
|
|
$events->listen('*', HandleMediaStorage::class); |
|
42
|
|
|
$events->listen('*', RemovePolymorphicLink::class); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get the services provided by the provider. |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function provides() |
|
51
|
|
|
{ |
|
52
|
|
|
return array(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function registerBindings() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->app->bind(FileRepository::class, function ($app) { |
|
58
|
|
|
return new EloquentFileRepository(new File(), $app['filesystem.disk']); |
|
|
|
|
|
|
59
|
|
|
}); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Register all commands for this module |
|
64
|
|
|
*/ |
|
65
|
|
|
private function registerCommands() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->registerRefreshCommand(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Register the refresh thumbnails command |
|
72
|
|
|
*/ |
|
73
|
|
|
private function registerRefreshCommand() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->app->bindShared('command.media.refresh', function ($app) { |
|
76
|
|
|
return new RefreshThumbnailCommand($app['Modules\Media\Repositories\FileRepository']); |
|
77
|
|
|
}); |
|
78
|
|
|
|
|
79
|
|
|
$this->commands('command.media.refresh'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
private function registerMaxFolderSizeValidator() |
|
83
|
|
|
{ |
|
84
|
|
|
Validator::extend('max_size', '\Modules\Media\Validators\MaxFolderSizeValidator@validateMaxSize'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: