Passed
Push — master ( 35232d...8d0b59 )
by Melech
06:16 queued 02:04
created

ServiceProvider::publishNullClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Http\Client\Provider;
15
16
use GuzzleHttp\Client as Guzzle;
17
use Valkyrja\Container\Contract\Container;
18
use Valkyrja\Container\Support\Provider;
19
use Valkyrja\Http\Client\Contract\Client;
20
use Valkyrja\Http\Client\GuzzleClient;
21
use Valkyrja\Http\Client\LogClient;
22
use Valkyrja\Http\Client\NullClient;
23
use Valkyrja\Http\Message\Factory\Contract\ResponseFactory;
24
use Valkyrja\Log\Contract\Logger;
25
26
/**
27
 * Class ServiceProvider.
28
 *
29
 * @author Melech Mizrachi
30
 */
31
final class ServiceProvider extends Provider
32
{
33
    /**
34
     * @inheritDoc
35
     */
36
    public static function publishers(): array
37
    {
38
        return [
39
            Client::class       => [self::class, 'publishClient'],
40
            GuzzleClient::class => [self::class, 'publishGuzzleClient'],
41
            Guzzle::class       => [self::class, 'publishGuzzle'],
42
            LogClient::class    => [self::class, 'publishLogClient'],
43
            NullClient::class   => [self::class, 'publishNullClient'],
44
        ];
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public static function provides(): array
51
    {
52
        return [
53
            Client::class,
54
            GuzzleClient::class,
55
            Guzzle::class,
56
            LogClient::class,
57
            NullClient::class,
58
        ];
59
    }
60
61
    /**
62
     * Publish the client service.
63
     */
64
    public static function publishClient(Container $container): void
65
    {
66
        $container->setSingleton(
67
            Client::class,
68
            $container->getSingleton(GuzzleClient::class)
69
        );
70
    }
71
72
    /**
73
     * Publish the GuzzleClient service.
74
     */
75
    public static function publishGuzzleClient(Container $container): void
76
    {
77
        $container->setSingleton(
78
            GuzzleClient::class,
79
            new GuzzleClient(
80
                $container->getSingleton(Guzzle::class),
81
                $container->getSingleton(ResponseFactory::class),
82
            )
83
        );
84
    }
85
86
    /**
87
     * Publish the LogClient service.
88
     */
89
    public static function publishLogClient(Container $container): void
90
    {
91
        $container->setSingleton(
92
            LogClient::class,
93
            new LogClient(
94
                $container->getSingleton(Logger::class),
95
                $container->getSingleton(ResponseFactory::class),
96
            )
97
        );
98
    }
99
100
    /**
101
     * Publish the NullClient service.
102
     */
103
    public static function publishNullClient(Container $container): void
104
    {
105
        $container->setSingleton(
106
            NullClient::class,
107
            new NullClient(
108
                $container->getSingleton(ResponseFactory::class),
109
            )
110
        );
111
    }
112
113
    /**
114
     * Publish the Guzzle service.
115
     */
116
    public static function publishGuzzle(Container $container): void
117
    {
118
        $container->setSingleton(
119
            Guzzle::class,
120
            new Guzzle()
121
        );
122
    }
123
}
124