Completed
Push — master ( bdb1b7...0d1a59 )
by dotzero
11s
created

ParamsBag::getProxy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AmoCRM\Request;
4
5
/**
6
 * Class ParamsBag
7
 *
8
 * Класс для хранения аргументов
9
 *
10
 * @package AmoCRM\Request
11
 * @author dotzero <[email protected]>
12
 * @link http://www.dotzero.ru/
13
 * @link https://github.com/dotzero/amocrm-php
14
 *
15
 * For the full copyright and license information, please view the LICENSE
16
 * file that was distributed with this source code.
17
 */
18
class ParamsBag
19
{
20
    /**
21
     * @var array Список значений параметров для авторизации
22
     */
23
    private $authParams = [];
24
25
    /**
26
     * @var array Список значений GET параметров
27
     */
28
    private $getParams = [];
29
30
    /**
31
     * @var array Список значений POST параметров
32
     */
33
    private $postParams = [];
34
35
    /**
36
     * @var string|null Прокси сервер
37
     */
38
    private $proxy = null;
39
40
    /**
41
     * Добавление прокси сервера
42
     *
43
     * @param string $proxy Прокси сервер CURLOPT_PROXY
44
     * @see http://php.net/manual/ru/function.curl-setopt.php
45
     * @return $this
46
     */
47
    public function addProxy($proxy)
48
    {
49
        $this->proxy = $proxy;
50
51
        return $this;
52
    }
53
54
    /**
55
     * Добавление значений параметров для авторизации
56
     *
57
     * @param string $name Название параметра
58
     * @param mixed $value Значение параметра
59
     * @return $this
60
     */
61 50
    public function addAuth($name, $value)
62
    {
63 50
        $this->authParams[$name] = $value;
64
65 50
        return $this;
66
    }
67
68
    /**
69
     * Получение параметра для авторизации по ключу или список параметров
70
     *
71
     * @param string $name Название параметра
72
     * @return array|null Значение параметра или список параметров
73
     */
74 11
    public function getAuth($name = null)
75
    {
76 11
        if ($name !== null) {
77 11
            return isset($this->authParams[$name]) ? $this->authParams[$name] : null;
78
        }
79
80 4
        return $this->authParams;
81
    }
82
83
    /**
84
     * Добавление значений GET параметров
85
     *
86
     * @param string|array $name Название параметра
87
     * @param mixed $value Значение параметра
88
     * @return $this
89
     */
90 3
    public function addGet($name, $value = null)
91
    {
92 3
        if (is_array($name) && $value === null) {
93 2
            $this->getParams = array_merge($this->getParams, $name);
94 2
        } else {
95 2
            $this->getParams[$name] = $value;
96
        }
97
98 3
        return $this;
99
    }
100
101
    /**
102
     * Получение GET параметра по ключу или список параметров
103
     *
104
     * @param string $name Название параметра
105
     * @return array|null Значение параметра или список параметров
106
     */
107 3
    public function getGet($name = null)
108
    {
109 3
        if ($name !== null) {
110 1
            return isset($this->getParams[$name]) ? $this->getParams[$name] : null;
111
        }
112
113 3
        return $this->getParams;
114
    }
115
116
    /**
117
     * Получение количества GET параметров
118
     *
119
     * @return int количество GET параметров
120
     */
121 1
    public function hasGet()
122
    {
123 1
        return count($this->getParams) ? true : false;
124
    }
125
126
    /**
127
     * Очистка всех GET параметров
128
     *
129
     * @return $this
130
     */
131 19
    public function clearGet()
132
    {
133 19
        $this->getParams = [];
134
135 19
        return $this;
136
    }
137
138
    /**
139
     * Добавление значений POST параметров
140
     *
141
     * @param string|array $name Название параметра
142
     * @param mixed $value Значение параметра
143
     * @return $this
144
     */
145 2
    public function addPost($name, $value = null)
146
    {
147 2
        if (is_array($name) && $value === null) {
148 2
            $this->postParams = array_merge($this->postParams, $name);
149 2
        } else {
150 1
            $this->postParams[$name] = $value;
151
        }
152
153 2
        return $this;
154
    }
155
156
    /**
157
     * Получение POST параметра по ключу или список параметров
158
     *
159
     * @param string $name Название параметра
160
     * @return array|null Значение параметра или список параметров
161
     */
162 1
    public function getPost($name = null)
163
    {
164 1
        if ($name !== null) {
165 1
            return isset($this->postParams[$name]) ? $this->postParams[$name] : null;
166
        }
167
168 1
        return $this->postParams;
169
    }
170
171
    /**
172
     * Получение количества POST параметров
173
     *
174
     * @return int количество POST параметров
175
     */
176 1
    public function hasPost()
177
    {
178 1
        return count($this->postParams) ? true : false;
179
    }
180
181
    /**
182
     * Очистка всех POST параметров
183
     *
184
     * @return $this
185
     */
186 19
    public function clearPost()
187
    {
188 19
        $this->postParams = [];
189
190 19
        return $this;
191
    }
192
193
    /**
194
     * Получить прокси сервер
195
     *
196
     * @return string
197
     */
198
    public function getProxy()
199
    {
200
        return $this->proxy;
201
    }
202
203
    /**
204
     * Получение использованиея прокси сервера
205
     *
206
     * @return bool
207
     */
208
    public function hasProxy()
209
    {
210
        return is_string($this->proxy);
211
    }
212
}
213