Completed
Push — master ( 6afef5...701ec0 )
by Dan Michael O.
16:21 queued 14:10
created

HttpClientProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Colligator\Providers;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
7
use Http\Client\HttpClient;
8
use Http\Message\MessageFactory;
9
use Http\Message\MessageFactory\GuzzleMessageFactory;
10
11
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
12
13
class HttpClientProvider extends ServiceProvider
14
{
15
    /**
16
     * Indicates if loading of the provider is deferred.
17
     *
18
     * @var bool
19
     */
20
    protected $defer = true;
21
22
    /**
23
     * Register the service provider.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        $this->app->singleton(HttpClient::class, function () {
30
            $config = ['timeout' => 30];
31
            $client = new GuzzleClient($config);
32
            $adapter = new GuzzleAdapter($client);
33
34
            return $adapter;
35
        });
36
37
        $this->app->singleton(MessageFactory::class, function () {
38
            $factory = new GuzzleMessageFactory();
39
40
            return $factory;
41
        });
42
    }
43
44
    /**
45
     * Get the services provided by the provider.
46
     *
47
     * @return array
48
     */
49
    public function provides()
50
    {
51
        return [
52
            HttpClient::class,
53
            MessageFactory::class,
54
        ];
55
    }
56
}
57