1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larium\Pay; |
4
|
|
|
|
5
|
|
|
use Iterator; |
6
|
|
|
use ArrayAccess; |
7
|
|
|
|
8
|
|
|
class ParamsBag implements Iterator, ArrayAccess |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The array of option values. |
12
|
|
|
* |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private $params = array(); |
16
|
|
|
|
17
|
18 |
|
public function __construct(array $params = array()) |
18
|
|
|
{ |
19
|
18 |
|
$this->params = $params; |
20
|
18 |
|
} |
21
|
|
|
|
22
|
8 |
|
public function get($name, $default = null) |
23
|
|
|
{ |
24
|
8 |
|
return $this->offsetExists($name) |
25
|
|
|
? $this->offsetGet($name) |
26
|
8 |
|
: $default; |
27
|
|
|
} |
28
|
|
|
|
29
|
1 |
|
public function __get($name) |
30
|
|
|
{ |
31
|
1 |
|
return $this->offsetGet($name); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function __set($name, $value) |
35
|
|
|
{ |
36
|
|
|
$this->offsetSet($name, $value); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function __isset($name) |
40
|
|
|
{ |
41
|
|
|
return $this->offsetExists($name); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns an array from params. |
46
|
|
|
* |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function getArrayCopy() |
50
|
|
|
{ |
51
|
|
|
return $this->params; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function rewind() |
58
|
|
|
{ |
59
|
|
|
reset($this->params); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function current() |
66
|
|
|
{ |
67
|
|
|
return current($this->params); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function key() |
74
|
|
|
{ |
75
|
|
|
return key($this->params); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function next() |
82
|
|
|
{ |
83
|
|
|
next($this->params); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function valid() |
90
|
|
|
{ |
91
|
|
|
return current($this->params) !== false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function offsetSet($offset, $value) |
98
|
|
|
{ |
99
|
|
|
if (is_null($offset)) { |
100
|
|
|
$this->params[] = $value; |
101
|
|
|
} else { |
102
|
|
|
$this->params[$offset] = $value; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
8 |
|
public function offsetExists($offset) |
110
|
|
|
{ |
111
|
8 |
|
return array_key_exists($offset, $this->params); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritdoc} |
116
|
|
|
*/ |
117
|
|
|
public function offsetUnset($offset) |
118
|
|
|
{ |
119
|
|
|
unset($this->params[$offset]); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* {@inheritdoc} |
124
|
|
|
*/ |
125
|
1 |
|
public function offsetGet($offset) |
126
|
|
|
{ |
127
|
1 |
|
$value = isset($this->params[$offset]) |
128
|
1 |
|
? $this->params[$offset] |
129
|
1 |
|
: null; |
130
|
|
|
|
131
|
1 |
|
if (is_array($value)) { |
132
|
|
|
return new self($value); |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
return $value; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|