Completed
Branch add-psr-18-support (b79d4b)
by Steven
02:51
created

Client::setAuthorization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Stevenmaguire\Services\Trello;
4
5
use Psr\Http\Client\ClientInterface;
6
use Psr\Http\Message\RequestFactoryInterface;
7
use Psr\Http\Message\StreamFactoryInterface;
8
9
class Client
10
{
11
    use Traits\ApiMethodsTrait,
12
        Traits\AuthorizationTrait,
13
        Traits\BatchTrait,
14
        Traits\ConfigurationTrait,
15
        Traits\SearchTrait;
16
17
    /**
18
     * Default client options
19
     *
20
     * @var array
21
     */
22
    protected static $defaultOptions = [
23
        'domain' => 'https://trello.com',
24
        'key' => null,
25
        'proxy' => null,
26
        'version' => '1',
27
        'secret' => null,
28
    ];
29
30
    /**
31
     * Authorization broker
32
     *
33
     * @var Authorization
34
     */
35
    protected $authorization;
36
37
    /**
38
     * Http broker
39
     *
40
     * @var Http
41
     */
42
    protected $http;
43
44
    /**
45
     * Creates new trello client.
46
     *
47
     * @param array $options
48
     */
49
    public function __construct($options = [])
50
    {
51
        Configuration::setMany($options, static::$defaultOptions);
52
53
        $this->http = new Http;
54
    }
55
56
    /**
57
     * Retrieves the authorization broker.
58
     *
59
     * @return Stevenmaguire\Services\Trello\Authorization
60
     */
61
    public function getAuthorization()
62
    {
63
        if (is_null($this->authorization)) {
64
            $this->authorization = new Authorization;
65
        }
66
67
        return $this->authorization;
68
    }
69
70
    /**
71
     * Retrieves currently configured http broker.
72
     *
73
     * @return Stevenmaguire\Services\Trello\Http
74
     */
75
    public function getHttp()
76
    {
77
        return $this->http;
78
    }
79
80
    /**
81
     * Updates the authorization broker.
82
     *
83
     * @param Authorization $authorization
84
     *
85
     * @return Client
86
     */
87
    public function setAuthorization(Authorization $authorization)
88
    {
89
        $this->authorization = $authorization;
90
91
        return $this;
92
    }
93
94
    /**
95
     * Updates the http client used by http broker.
96
     *
97
     * @param ClientInterface  $httpClient
98
     *
99
     * @return Client
100
     */
101
    public function setHttpClient(ClientInterface $httpClient)
102
    {
103
        $this->http->setClient($httpClient);
104
105
        return $this;
106
    }
107
108
    /**
109
     * Updates the http request factory used by http broker.
110
     *
111
     * @param RequestFactoryInterface  $httpRequestFactory
112
     *
113
     * @return Client
114
     */
115
    public function setHttpRequestFactory(RequestFactoryInterface $httpRequestFactory)
116
    {
117
        $this->http->setRequestFactory($httpRequestFactory);
118
119
        return $this;
120
    }
121
122
    /**
123
     * Updates the http stream factory used by http broker.
124
     *
125
     * @param StreamFactoryInterface  $httpStreamFactory
126
     *
127
     * @return Client
128
     */
129
    public function setHttpStreamFactory(StreamFactoryInterface $httpStreamFactory)
130
    {
131
        $this->http->setStreamFactory($httpStreamFactory);
132
133
        return $this;
134
    }
135
}
136