1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Laravel HTTP adapter. |
5
|
|
|
* |
6
|
|
|
* (c) Hidde Beydals <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace HiddeCo\HttpAdapter; |
13
|
|
|
|
14
|
|
|
use Illuminate\Contracts\Foundation\Application; |
15
|
|
|
use Illuminate\Support\ServiceProvider; |
16
|
|
|
use Ivory\HttpAdapter\Configuration; |
17
|
|
|
use Ivory\HttpAdapter\HttpAdapterFactory as AdapterFactory; |
18
|
|
|
use Ivory\HttpAdapter\HttpAdapterInterface; |
19
|
|
|
|
20
|
|
|
class HttpAdapterServiceProvider extends ServiceProvider |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Boot the service provider. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function boot() |
28
|
|
|
{ |
29
|
|
|
$this->mergeConfig(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Merge the config files. |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
protected function mergeConfig() |
38
|
|
|
{ |
39
|
|
|
$src = realpath(__DIR__.'/../config/httpadapter.php'); |
40
|
|
|
|
41
|
|
|
if (class_exists('Illuminate\Foundation\Application', false)) { |
42
|
|
|
$this->publishes([$src => config_path('httpadapter.php')]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->mergeConfigFrom($src, 'httpadapter'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Register the service provider. |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function register() |
54
|
|
|
{ |
55
|
|
|
$this->registerAdapterFactory($this->app); |
56
|
|
|
$this->registerConfigurationFactory($this->app); |
57
|
|
|
$this->registerHttpAdapterFactory($this->app); |
58
|
|
|
$this->registerManager($this->app); |
59
|
|
|
$this->registerBindings($this->app); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
*/ |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Register the adapter factory class. |
68
|
|
|
* |
69
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
protected function registerAdapterFactory(Application $app) |
74
|
|
|
{ |
75
|
|
|
$app->singleton('httpadapter.adapterfactory', function () { |
76
|
|
|
return new AdapterFactory(); |
77
|
|
|
}); |
78
|
|
|
|
79
|
|
|
$app->alias('httpadapter.adapterfactory', AdapterFactory::class); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Register the configuration factory class. |
84
|
|
|
* |
85
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
86
|
|
|
* |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
protected function registerConfigurationFactory(Application $app) |
90
|
|
|
{ |
91
|
|
|
$app->singleton('httpadapter.configurationfactory', function ($app) { |
|
|
|
|
92
|
|
|
$configuration = new Configuration(); |
93
|
|
|
|
94
|
|
|
return new ConfigurationFactory($configuration); |
95
|
|
|
}); |
96
|
|
|
|
97
|
|
|
$app->alias('httpadapter.configurationfactory', ConfigurationFactory::class); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Register the HTTP adapter factory class. |
102
|
|
|
* |
103
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
104
|
|
|
* |
105
|
|
|
* @return void |
106
|
|
|
*/ |
107
|
|
|
protected function registerHttpAdapterFactory(Application $app) |
108
|
|
|
{ |
109
|
|
|
$app->singleton('httpadapter.factory', function ($app) { |
110
|
|
|
$adapter = $app['httpadapter.adapterfactory']; |
111
|
|
|
$configuration = $app['httpadapter.configurationfactory']; |
112
|
|
|
$eventDispatcher = $app->make('HiddeCo\HttpAdapter\Adapters\AbstractEventDispatcher'); |
113
|
|
|
|
114
|
|
|
return new HttpAdapterFactory($adapter, $configuration, $eventDispatcher); |
115
|
|
|
}); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Register the manager class. |
120
|
|
|
* |
121
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
122
|
|
|
* |
123
|
|
|
* @return void |
124
|
|
|
*/ |
125
|
|
|
protected function registerManager(Application $app) |
126
|
|
|
{ |
127
|
|
|
$app->singleton('httpadapter', function ($app) { |
128
|
|
|
$config = $app['config']; |
129
|
|
|
$factory = $app['httpadapter.factory']; |
130
|
|
|
|
131
|
|
|
return new HttpAdapterManager($config, $factory); |
132
|
|
|
}); |
133
|
|
|
|
134
|
|
|
$app->alias('httpadapter', HttpAdapterManager::class); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Register the bindings. |
139
|
|
|
* |
140
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
protected function registerBindings(Application $app) |
145
|
|
|
{ |
146
|
|
|
$app->bind( |
147
|
|
|
'Symfony\Component\EventDispatcher\EventDispatcherInterface', |
148
|
|
|
'Symfony\Component\EventDispatcher\EventDispatcher' |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
$app->bind( |
152
|
|
|
'HiddeCo\HttpAdapter\Adapters\AbstractEventDispatcher', |
153
|
|
|
'HiddeCo\HttpAdapter\Adapters\EventDispatcherLaravel' |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
$app->bind('httpadapter.connection', function ($app) { |
157
|
|
|
$manager = $app['httpadapter']; |
158
|
|
|
|
159
|
|
|
return $manager->connection(); |
160
|
|
|
}); |
161
|
|
|
|
162
|
|
|
$app->alias('httpadapter.connection', HttpAdapterInterface::class); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get the services provided by the provider. |
167
|
|
|
* |
168
|
|
|
* @return string[] |
169
|
|
|
*/ |
170
|
|
|
public function provides() |
171
|
|
|
{ |
172
|
|
|
return [ |
173
|
|
|
'httpadapter.adapterfactory', |
174
|
|
|
'httpadapter.configurationfactory', |
175
|
|
|
'httpadapter.factory', |
176
|
|
|
'httpadapter', |
177
|
|
|
'httpadapter.connection', |
178
|
|
|
]; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.