1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* php-guard/curl <https://github.com/php-guard/curl> |
4
|
|
|
* Copyright (C) ${YEAR} by Alexandre Le Borgne <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License |
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace PhpGuard\Curl; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class CurlOptions implements \ArrayAccess |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private $options; |
29
|
|
|
|
30
|
12 |
|
public function __construct(array $options = []) |
31
|
|
|
{ |
32
|
12 |
|
$this->options = $options; |
33
|
12 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Whether a offset exists |
37
|
|
|
* @link https://php.net/manual/en/arrayaccess.offsetexists.php |
38
|
|
|
* @param mixed $offset <p> |
39
|
|
|
* An offset to check for. |
40
|
|
|
* </p> |
41
|
|
|
* @return boolean true on success or false on failure. |
42
|
|
|
* </p> |
43
|
|
|
* <p> |
44
|
|
|
* The return value will be casted to boolean if non-boolean was returned. |
45
|
|
|
* @since 5.0.0 |
46
|
|
|
*/ |
47
|
|
|
public function offsetExists($offset) |
48
|
|
|
{ |
49
|
|
|
return isset($this->options[$offset]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Offset to retrieve |
54
|
|
|
* @link https://php.net/manual/en/arrayaccess.offsetget.php |
55
|
|
|
* @param mixed $offset <p> |
56
|
|
|
* The offset to retrieve. |
57
|
|
|
* </p> |
58
|
|
|
* @return mixed Can return all value types. |
59
|
|
|
* @since 5.0.0 |
60
|
|
|
*/ |
61
|
|
|
public function offsetGet($offset) |
62
|
|
|
{ |
63
|
|
|
return $this->options[$offset] ?? null; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Offset to set |
68
|
|
|
* @link https://php.net/manual/en/arrayaccess.offsetset.php |
69
|
|
|
* @param mixed $offset <p> |
70
|
|
|
* The offset to assign the value to. |
71
|
|
|
* </p> |
72
|
|
|
* @param mixed $value <p> |
73
|
|
|
* The value to set. |
74
|
|
|
* </p> |
75
|
|
|
* @return void |
76
|
|
|
* @since 5.0.0 |
77
|
|
|
*/ |
78
|
|
|
public function offsetSet($offset, $value) |
79
|
|
|
{ |
80
|
|
|
$this->options[$offset] = $value; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Offset to unset |
85
|
|
|
* @link https://php.net/manual/en/arrayaccess.offsetunset.php |
86
|
|
|
* @param mixed $offset <p> |
87
|
|
|
* The offset to unset. |
88
|
|
|
* </p> |
89
|
|
|
* @return void |
90
|
|
|
* @since 5.0.0 |
91
|
|
|
*/ |
92
|
|
|
public function offsetUnset($offset) |
93
|
|
|
{ |
94
|
|
|
unset($this->options[$offset]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function replace(CurlOptions $options) |
98
|
|
|
{ |
99
|
|
|
return new self(array_replace($this->options, $options->all())); |
100
|
|
|
} |
101
|
|
|
|
102
|
12 |
|
public function all() |
103
|
|
|
{ |
104
|
12 |
|
return $this->options; |
105
|
|
|
} |
106
|
|
|
} |