|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JeroenG\LaravelPhotoGallery; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
|
|
7
|
|
|
class LaravelPhotoGalleryServiceProvider extends ServiceProvider |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Indicates if loading of the provider is deferred. |
|
11
|
|
|
* |
|
12
|
|
|
* @var bool |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $defer = false; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Bootstrap the application events. |
|
18
|
|
|
* |
|
19
|
|
|
* @return void |
|
20
|
|
|
*/ |
|
21
|
|
|
public function boot() |
|
22
|
|
|
{ |
|
23
|
|
|
$resources = realpath(__DIR__.'/../resources'); |
|
24
|
|
|
|
|
25
|
|
|
$this->loadViewsFrom($resources.'/views', 'gallery'); |
|
26
|
|
|
$this->loadTranslationsFrom($resources.'/lang', 'gallery'); |
|
27
|
|
|
|
|
28
|
|
|
$this->publishes([ |
|
29
|
|
|
$resources.'/views' => base_path('resources/views/vendor/gallery') |
|
30
|
|
|
], 'views'); |
|
31
|
|
|
|
|
32
|
|
|
$this->publishes([ |
|
33
|
|
|
$resources.'/config/gallery.php' => config_path('gallery.php') |
|
34
|
|
|
], 'config'); |
|
35
|
|
|
|
|
36
|
|
|
$this->publishes([ |
|
37
|
|
|
$resources.'/migrations' => $this->app->databasePath().'/migrations', |
|
|
|
|
|
|
38
|
|
|
], 'migrations'); |
|
39
|
|
|
|
|
40
|
|
|
$this->publishes([ |
|
41
|
|
|
$resources.'/assets' => public_path('vendor/gallery'), |
|
42
|
|
|
], 'assets'); |
|
43
|
|
|
|
|
44
|
|
|
if(config('gallery.routes')) { |
|
45
|
|
|
if (! $this->app->routesAreCached()) { |
|
|
|
|
|
|
46
|
|
|
require $resources.'/routes.php'; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Register the service provider. |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
public function register() |
|
57
|
|
|
{ |
|
58
|
|
|
$resources = realpath(__DIR__.'/../resources'); |
|
59
|
|
|
$this->mergeConfigFrom($resources.'/config/gallery.php', 'gallery'); |
|
60
|
|
|
$this->bindBindings(); |
|
61
|
|
|
$this->commands(['JeroenG\LaravelPhotoGallery\Console\GalleryClearCommand']); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the services provided by the provider. |
|
66
|
|
|
* |
|
67
|
|
|
* @return array |
|
68
|
|
|
*/ |
|
69
|
|
|
public function provides() |
|
70
|
|
|
{ |
|
71
|
|
|
return ['gallery']; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function bindBindings() |
|
75
|
|
|
{ |
|
76
|
|
|
// Bind the facade |
|
77
|
|
|
$this->app->bind('gallery', function() { |
|
78
|
|
|
$photo = $this->app->make('JeroenG\LaravelPhotoGallery\Contracts\PhotoAdapter'); |
|
79
|
|
|
$album = $this->app->make('JeroenG\LaravelPhotoGallery\Contracts\AlbumAdapter'); |
|
80
|
|
|
$user = $this->app->make('JeroenG\LaravelPhotoGallery\Contracts\UserAdapter'); |
|
81
|
|
|
$tag = $this->app->make('JeroenG\LaravelPhotoGallery\Contracts\TagAdapter'); |
|
82
|
|
|
return new Services\GalleryService($album, $photo, $user, $tag); |
|
83
|
|
|
}); |
|
84
|
|
|
|
|
85
|
|
|
// Bind the adapters |
|
86
|
|
|
if(config('gallery.adapter') == 'eloquent') { |
|
87
|
|
|
// When using 'AlbumRepository', Laravel automatically uses the EloquentAlbumRepository |
|
88
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\AlbumAdapter','JeroenG\LaravelPhotoGallery\Adapters\Eloquent\EloquentAlbumAdapter'); |
|
89
|
|
|
// The same for Photos |
|
90
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\PhotoAdapter', 'JeroenG\LaravelPhotoGallery\Adapters\Eloquent\EloquentPhotoAdapter'); |
|
91
|
|
|
// And for Users |
|
92
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\UserAdapter', 'JeroenG\LaravelPhotoGallery\Adapters\Eloquent\EloquentUserAdapter'); |
|
93
|
|
|
// And Tags |
|
94
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\TagAdapter', 'JeroenG\LaravelPhotoGallery\Adapters\Eloquent\EloquentTagAdapter'); |
|
95
|
|
|
} elseif (config('gallery.adapter') == 'memory') { |
|
96
|
|
|
// When using 'AlbumRepository', Laravel automatically uses the EloquentAlbumRepository |
|
97
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\AlbumAdapter','JeroenG\LaravelPhotoGallery\Adapters\InMemory\InMemoryAlbumAdapter'); |
|
98
|
|
|
// The same for Photos |
|
99
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\PhotoAdapter', 'JeroenG\LaravelPhotoGallery\Adapters\InMemory\InMemoryPhotoAdapter'); |
|
100
|
|
|
// And for Users |
|
101
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\UserAdapter', 'JeroenG\LaravelPhotoGallery\Adapters\InMemory\InMemoryUserAdapter'); |
|
102
|
|
|
// And Tags |
|
103
|
|
|
$this->app->bind('JeroenG\LaravelPhotoGallery\Contracts\TagAdapter', 'JeroenG\LaravelPhotoGallery\Adapters\InMemory\InMemoryTagAdapter'); |
|
104
|
|
|
} else { |
|
105
|
|
|
throw new \Exception("Invalid gallery adapter."); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
} |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.