commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
lib
commercetools-base
src
Base
MapperScalarSequence.php
1
<?php
2
3
declare(strict_types=1);
10
namespace
Commercetools\Base
;
11
12
use stdClass;
13
18
abstract
class
MapperScalarSequence
implements
CSequence
19
{
21
private
$data;
23
private
$indexes = [];
25
private
$iterator;
26
31
final
public
function
__construct
(array $data =
null
)
32
{
33
if
(!is_null($data)) {
34
$this->
index
($data);
35
}
36
$this->data = $data;
37
$this->iterator = $this->
getIterator
();
38
}
39
40
public
function
toArray
(): ?array
41
{
42
return
$this->data;
43
}
44
45
#[\ReturnTypeWillChange]
46
public
function
jsonSerialize
(): ?array
47
{
48
return
$this->data;
49
}
50
56
final
public
static
function
fromArray
(array $data)
57
{
58
return
new
static
($data);
59
}
60
64
protected
function
index
($data): void
65
{
66
}
67
71
final
protected
function
get
(?
int
$index)
72
{
73
if
(isset($this->data[$index])) {
74
return
$this->data[$index];
75
}
76
return
null
;
77
}
78
82
final
protected
function
set
($data, ?
int
$index): void
83
{
84
if
(is_null($index)) {
85
$this->data[] = $data;
86
}
else
{
87
$this->data[$index] = $data;
88
}
89
}
90
96
public
function
add
($value)
97
{
98
return
$this->
store
($value);
99
}
100
106
final
protected
function
store
($value)
107
{
108
$this->
set
($value,
null
);
109
$this->iterator = $this->
getIterator
();
110
111
return
$this;
112
}
113
117
public
function
at
(
int
$index)
118
{
119
return
$this->
mapper
()($index);
120
}
121
125
abstract
protected
function
mapper
();
126
127
final
protected
function
addToIndex
(
string
$field,
string
$key,
int
$index): void
128
{
129
$this->indexes[$field][$key] = $index;
130
}
131
135
final
protected
function
valueByKey
(
string
$field,
string
$key)
136
{
137
return
isset($this->indexes[$field][$key]) ? $this->
at
($this->indexes[$field][$key]) :
null
;
138
}
139
140
public
function
getIterator
():
MapperIterator
141
{
142
$keys = !is_null($this->data) ? array_keys($this->data) : [];
143
$keyIterator = new \ArrayIterator(array_combine($keys, $keys));
144
$iterator =
new
MapperIterator
(
145
$keyIterator,
146
$this->
mapper
()
147
);
148
$iterator->rewind();
149
150
return
$iterator;
151
}
152
156
public
function
current
()
157
{
159
return
$this->iterator->current();
160
}
161
165
public
function
end
()
166
{
167
if
($this->data ==
null
) {
168
return
null
;
169
}
170
$arrayKeys = array_keys($this->data);
171
$lastKey = array_pop($arrayKeys);
172
173
return
$this->
at
($lastKey);
174
}
175
179
public
function
next
()
180
{
181
$this->iterator->next();
182
}
183
187
public
function
key
()
188
{
190
return
$this->iterator->key();
191
}
192
196
public
function
valid
()
197
{
198
return
$this->iterator->valid();
199
}
200
204
public
function
rewind
()
205
{
206
$this->iterator->rewind();
207
}
208
213
public
function
offsetExists
($offset)
214
{
215
return
!is_null($this->data) && array_key_exists($offset, $this->data);
216
}
217
222
public
function
offsetGet
($offset)
223
{
224
return
$this->
at
($offset);
225
}
226
233
public
function
offsetSet
($offset, $value)
234
{
235
$this->
set
($value, $offset);
236
$this->iterator = $this->
getIterator
();
237
}
238
243
public
function
offsetUnset
($offset)
244
{
245
if
($this->
offsetExists
($offset)) {
247
unset($this->data[$offset]);
248
$this->iterator = $this->
getIterator
();
249
}
250
}
251
255
final
public
static
function
of
()
256
{
257
return
new
static
();
258
}
259
}
Commercetools\Base\MapperIterator
Definition
MapperIterator.php:13
Commercetools\Base\MapperScalarSequence
Definition
MapperScalarSequence.php:19
Commercetools\Base\MapperScalarSequence\index
index($data)
Definition
MapperScalarSequence.php:64
Commercetools\Base\MapperScalarSequence\end
end()
Definition
MapperScalarSequence.php:165
Commercetools\Base\MapperScalarSequence\valueByKey
valueByKey(string $field, string $key)
Definition
MapperScalarSequence.php:135
Commercetools\Base\MapperScalarSequence\rewind
rewind()
Definition
MapperScalarSequence.php:204
Commercetools\Base\MapperScalarSequence\getIterator
getIterator()
Definition
MapperScalarSequence.php:140
Commercetools\Base\MapperScalarSequence\offsetSet
offsetSet($offset, $value)
Definition
MapperScalarSequence.php:233
Commercetools\Base\MapperScalarSequence\offsetGet
offsetGet($offset)
Definition
MapperScalarSequence.php:222
Commercetools\Base\MapperScalarSequence\valid
valid()
Definition
MapperScalarSequence.php:196
Commercetools\Base\MapperScalarSequence\__construct
__construct(array $data=null)
Definition
MapperScalarSequence.php:31
Commercetools\Base\MapperScalarSequence\offsetUnset
offsetUnset($offset)
Definition
MapperScalarSequence.php:243
Commercetools\Base\MapperScalarSequence\of
static of()
Definition
MapperScalarSequence.php:255
Commercetools\Base\MapperScalarSequence\current
current()
Definition
MapperScalarSequence.php:156
Commercetools\Base\MapperScalarSequence\next
next()
Definition
MapperScalarSequence.php:179
Commercetools\Base\MapperScalarSequence\key
key()
Definition
MapperScalarSequence.php:187
Commercetools\Base\MapperScalarSequence\toArray
toArray()
Definition
MapperScalarSequence.php:40
Commercetools\Base\MapperScalarSequence\addToIndex
addToIndex(string $field, string $key, int $index)
Definition
MapperScalarSequence.php:127
Commercetools\Base\MapperScalarSequence\mapper
mapper()
Commercetools\Base\MapperScalarSequence\fromArray
static fromArray(array $data)
Definition
MapperScalarSequence.php:56
Commercetools\Base\MapperScalarSequence\store
store($value)
Definition
MapperScalarSequence.php:106
Commercetools\Base\MapperScalarSequence\at
at(int $index)
Definition
MapperScalarSequence.php:117
Commercetools\Base\MapperScalarSequence\offsetExists
offsetExists($offset)
Definition
MapperScalarSequence.php:213
Commercetools\Base\MapperScalarSequence\jsonSerialize
jsonSerialize()
Definition
MapperScalarSequence.php:46
Commercetools\Base\MapperScalarSequence\add
add($value)
Definition
MapperScalarSequence.php:96
Commercetools\Base\CSequence
Definition
CSequence.php:19
Commercetools\Base
Definition
MapperArraySequence.php:10
Generated by
1.9.8