author | ymh <ymh.work@gmail.com> |
Mon, 12 Jun 2017 14:53:59 +0200 | |
changeset 537 | d2e6ee099125 |
parent 533 | a557802f2b12 |
permissions | -rw-r--r-- |
23 | 1 |
<?php |
2 |
||
3 |
namespace CorpusParole\Providers; |
|
4 |
||
5 |
use Illuminate\Support\ServiceProvider; |
|
6 |
use GuzzleHttp\Client; |
|
7 |
||
8 |
/** |
|
9 |
* guzzle Service Provider, inspired by https://github.com/urakozz/laravel-guzzle |
|
10 |
*/ |
|
11 |
class GuzzleServiceProvider extends ServiceProvider |
|
12 |
{ |
|
533
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
13 |
|
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
14 |
private function bindToKey($key) { |
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
15 |
$this->app->bind($key, function() { |
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
16 |
$config = isset($this->app['config']['guzzle']) ? $this->app['config']['guzzle'] : []; |
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
17 |
return new Client($config); |
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
18 |
}); |
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
19 |
} |
23 | 20 |
/** |
21 |
* Register the Guzzle provider |
|
22 |
* |
|
23 |
* @return GuzzleClient |
|
24 |
*/ |
|
25 |
public function register() |
|
26 |
{ |
|
533
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
27 |
$this->bindToKey('Guzzle'); |
a557802f2b12
Make guzzle client use the proxy configuration when injected by the ioc
ymh <ymh.work@gmail.com>
parents:
139
diff
changeset
|
28 |
$this->bindToKey('GuzzleHttp\Client'); |
23 | 29 |
} |
30 |
} |