1
|
|
|
<?php namespace Modules\Media\Providers; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Validator; |
4
|
|
|
use Illuminate\Support\ServiceProvider; |
5
|
|
|
use Modules\Media\Console\RefreshThumbnailCommand; |
6
|
|
|
use Modules\Media\Entities\File; |
7
|
|
|
use Modules\Media\Image\Imagy; |
8
|
|
|
use Modules\Media\Image\Intervention\InterventionFactory; |
9
|
|
|
use Modules\Media\Image\ThumbnailsManager; |
10
|
|
|
use Modules\Media\Repositories\Eloquent\EloquentFileRepository; |
11
|
|
|
use Modules\Media\Validators\MaxFolderSizeValidator; |
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->app->booted(function () { |
30
|
|
|
$this->registerBindings(); |
31
|
|
|
}); |
32
|
|
|
$this->registerCommands(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function boot() |
36
|
|
|
{ |
37
|
|
|
$this->registerMaxFolderSizeValidator(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the services provided by the provider. |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function provides() |
46
|
|
|
{ |
47
|
|
|
return array(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function registerBindings() |
51
|
|
|
{ |
52
|
|
|
$this->app->bind( |
53
|
|
|
'Modules\Media\Repositories\FileRepository', |
54
|
|
|
function ($app) { |
55
|
|
|
return new EloquentFileRepository(new File(), $app['filesystem.disk']); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Register all commands for this module |
62
|
|
|
*/ |
63
|
|
|
private function registerCommands() |
64
|
|
|
{ |
65
|
|
|
$this->registerRefreshCommand(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Register the refresh thumbnails command |
70
|
|
|
*/ |
71
|
|
|
private function registerRefreshCommand() |
72
|
|
|
{ |
73
|
|
View Code Duplication |
$this->app->bindShared('command.media.refresh', function ($app) { |
74
|
|
|
$thumbnailManager = new ThumbnailsManager($app['config'], $app['modules']); |
|
|
|
|
75
|
|
|
$imagy = new Imagy(new InterventionFactory(), $thumbnailManager, $app['config']); |
76
|
|
|
|
77
|
|
|
return new RefreshThumbnailCommand($imagy, $app['Modules\Media\Repositories\FileRepository']); |
78
|
|
|
}); |
79
|
|
|
|
80
|
|
|
$this->commands( |
81
|
|
|
'command.media.refresh' |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function registerMaxFolderSizeValidator() |
86
|
|
|
{ |
87
|
|
|
Validator::resolver(function ($translator, $data, $rules, $messages, $attributes) { |
88
|
|
|
return new MaxFolderSizeValidator($translator, $data, $rules, $messages, $attributes); |
89
|
|
|
}); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.