1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Http\Httplug; |
4
|
|
|
|
5
|
|
|
use Http\Message\UriFactory; |
6
|
|
|
use Http\Message\StreamFactory; |
7
|
|
|
use Http\Message\MessageFactory; |
8
|
|
|
use Http\Message\ResponseFactory; |
9
|
|
|
use Illuminate\Support\ServiceProvider; |
10
|
|
|
use Http\Discovery\UriFactoryDiscovery; |
11
|
|
|
use Http\Discovery\StreamFactoryDiscovery; |
12
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
13
|
|
|
|
14
|
|
|
class HttplugServiceProvider extends ServiceProvider |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Indicates if loading of the provider is deferred. |
18
|
|
|
* |
19
|
|
|
* @var bool |
20
|
|
|
*/ |
21
|
|
|
protected $defer = true; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Bootstrap the application services. |
25
|
|
|
*/ |
26
|
5 |
|
public function boot() |
27
|
|
|
{ |
28
|
5 |
|
$source = __DIR__.'/../config/laravel-httplug.php'; |
29
|
5 |
|
$this->publishes([$source => config_path('httplug.php')], 'config'); |
30
|
5 |
|
$this->mergeConfigFrom($source, 'httplug'); |
31
|
5 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Register the application services. |
35
|
|
|
*/ |
36
|
5 |
|
public function register() |
37
|
|
|
{ |
38
|
5 |
|
$this->registerHttplugFactories(); |
39
|
5 |
|
$this->registerHttplug(); |
40
|
5 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Register php-http interfaces to container. |
44
|
|
|
*/ |
45
|
|
|
protected function registerHttplugFactories() |
46
|
|
|
{ |
47
|
5 |
|
$this->app->bind('httplug.message_factory.default', function ($app) { |
|
|
|
|
48
|
2 |
|
return MessageFactoryDiscovery::find(); |
49
|
5 |
|
}); |
50
|
|
|
$this->app->alias('httplug.message_factory.default', MessageFactory::class); |
51
|
|
|
$this->app->alias('httplug.message_factory.default', ResponseFactory::class); |
52
|
|
|
|
53
|
|
|
$this->app->bind('httplug.uri_factory.default', function ($app) { |
|
|
|
|
54
|
|
|
return UriFactoryDiscovery::find(); |
55
|
|
|
}); |
56
|
|
|
$this->app->alias('httplug.uri_factory.default', UriFactory::class); |
57
|
|
|
|
58
|
|
|
$this->app->bind('httplug.stream_factory.default', function ($app) { |
|
|
|
|
59
|
|
|
return StreamFactoryDiscovery::find(); |
60
|
|
|
}); |
61
|
|
|
$this->app->alias('httplug.stream_factory.default', StreamFactory::class); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Register httplug to container. |
66
|
|
|
*/ |
67
|
|
|
protected function registerHttplug() |
68
|
|
|
{ |
69
|
|
|
$this->app->singleton('httplug', function ($app) { |
70
|
|
|
return new HttplugManager($app); |
71
|
|
|
}); |
72
|
|
|
$this->app->alias('httplug', HttplugManager::class); |
73
|
|
|
|
74
|
|
|
$this->app->singleton('httplug.default', function ($app) { |
75
|
|
|
return $app['httplug']->driver(); |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the services provided by the provider. |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function provides() |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
|
|
'httplug', |
88
|
|
|
'httplug.default', |
89
|
|
|
'httplug.message_factory.default', |
90
|
|
|
'httplug.uri_factory.default', |
91
|
|
|
'httplug.stream_factory.default', |
92
|
|
|
MessageFactory::class, |
93
|
|
|
ResponseFactory::class, |
94
|
|
|
StreamFactory::class, |
95
|
|
|
UriFactory::class, |
96
|
|
|
|
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.