1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package php-tmdb\laravel |
5
|
|
|
* @author Mark Redeman <[email protected]> |
6
|
|
|
* @copyright (c) 2014, Mark Redeman |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Tmdb\Laravel; |
10
|
|
|
|
11
|
|
|
use Illuminate\Support\ServiceProvider; |
12
|
|
|
use Tmdb\ApiToken; |
13
|
|
|
use Tmdb\Client; |
14
|
|
|
use Tmdb\Laravel\Cache\DoctrineCacheBridge; |
15
|
|
|
use Tmdb\Laravel\EventDispatcher\EventDispatcherBridge; |
16
|
|
|
use Tmdb\Model\Configuration; |
17
|
|
|
use Tmdb\Repository\ConfigurationRepository; |
18
|
|
|
|
19
|
|
|
class TmdbServiceProvider extends ServiceProvider |
20
|
|
|
{ |
21
|
|
|
protected const CONFIG_PATH = __DIR__ . '/../config/tmdb.php'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Bootstrap the application events. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function boot() |
29
|
|
|
{ |
30
|
|
|
$this->publishes([ |
31
|
|
|
self::CONFIG_PATH => config_path('tmdb.php'), |
32
|
|
|
], 'config'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Register the service provider. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function register() |
41
|
|
|
{ |
42
|
|
|
$this->mergeConfigFrom(self::CONFIG_PATH, 'tmdb'); |
43
|
|
|
|
44
|
|
|
// Let the IoC container be able to make a Symfony event dispatcher |
45
|
|
|
$this->app->bindIf( |
46
|
|
|
'Symfony\Component\EventDispatcher\EventDispatcherInterface', |
47
|
|
|
'Symfony\Component\EventDispatcher\EventDispatcher' |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->app->singleton(Client::class, function ($app) { |
|
|
|
|
51
|
|
|
if (!config()->has('tmdb.cache.handler')) { |
52
|
|
|
$repository = app('cache')->store(config('tmdb.cache_store')); |
53
|
|
|
|
54
|
|
|
if (!empty(config('tmdb.cache_tag'))) { |
55
|
|
|
$repository = $repository->tags(config('tmdb.cache_tag')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
config()->set('tmdb.cache.handler', new DoctrineCacheBridge($repository)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (!config()->has('tmdb.event_dispatcher')) { |
62
|
|
|
config()->set('tmdb.event_dispatcher', $this->app->make(EventDispatcherBridge::class)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$token = new ApiToken(config('tmdb.api_key')); |
66
|
|
|
return new Client($token, config('tmdb.options')); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
// bind the configuration (used by the image helper) |
70
|
|
|
$this->app->bind(Configuration::class, function () { |
71
|
|
|
$configuration = $this->app->make(ConfigurationRepository::class); |
72
|
|
|
return $configuration->load(); |
73
|
|
|
}); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the services provided by the provider. |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function provides() |
82
|
|
|
{ |
83
|
|
|
return [ |
84
|
|
|
Client::class, |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.