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
MapperSequence.php
1
<?php
2
3
declare(strict_types=1);
10
namespace
Commercetools\Base
;
11
12
use stdClass;
13
18
abstract
class
MapperSequence
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
130
final
protected
function
addToIndex
(
string
$field,
string
$key,
int
$index): void
131
{
132
$this->indexes[$field][$key] = $index;
133
}
134
138
final
protected
function
valueByKey
(
string
$field,
string
$key)
139
{
140
return
isset($this->indexes[$field][$key]) ? $this->
at
($this->indexes[$field][$key]) :
null
;
141
}
142
143
public
function
getIterator
():
MapperIterator
144
{
145
$keys = !is_null($this->data) ? array_keys($this->data) : [];
146
$keyIterator = new \ArrayIterator(array_combine($keys, $keys));
147
$iterator =
new
MapperIterator
(
148
$keyIterator,
149
$this->
mapper
()
150
);
151
$iterator->rewind();
152
153
return
$iterator;
154
}
155
159
public
function
current
()
160
{
162
return
$this->iterator->current();
163
}
164
168
public
function
end
()
169
{
170
if
($this->data ==
null
) {
171
return
null
;
172
}
173
$arrayKeys = array_keys($this->data);
174
$lastKey = array_pop($arrayKeys);
175
176
return
$this->
at
($lastKey);
177
}
178
182
public
function
next
()
183
{
184
$this->iterator->next();
185
}
186
190
public
function
key
()
191
{
193
return
$this->iterator->key();
194
}
195
199
public
function
valid
()
200
{
201
return
$this->iterator->valid();
202
}
203
207
public
function
rewind
()
208
{
209
$this->iterator->rewind();
210
}
211
216
public
function
offsetExists
($offset)
217
{
218
return
!is_null($this->data) && array_key_exists($offset, $this->data);
219
}
220
225
public
function
offsetGet
($offset)
226
{
227
return
$this->
at
($offset);
228
}
229
236
public
function
offsetSet
($offset, $value)
237
{
238
$this->
set
($value, $offset);
239
$this->iterator = $this->
getIterator
();
240
}
241
246
public
function
offsetUnset
($offset)
247
{
248
if
($this->
offsetExists
($offset)) {
250
unset($this->data[$offset]);
251
$this->iterator = $this->
getIterator
();
252
}
253
}
254
258
final
public
static
function
of
()
259
{
260
return
new
static
();
261
}
262
}
Commercetools\Base\MapperIterator
Definition
MapperIterator.php:13
Commercetools\Base\MapperSequence
Definition
MapperSequence.php:19
Commercetools\Base\MapperSequence\offsetGet
offsetGet($offset)
Definition
MapperSequence.php:225
Commercetools\Base\MapperSequence\store
store($value)
Definition
MapperSequence.php:106
Commercetools\Base\MapperSequence\fromArray
static fromArray(array $data)
Definition
MapperSequence.php:56
Commercetools\Base\MapperSequence\offsetSet
offsetSet($offset, $value)
Definition
MapperSequence.php:236
Commercetools\Base\MapperSequence\add
add($value)
Definition
MapperSequence.php:96
Commercetools\Base\MapperSequence\rewind
rewind()
Definition
MapperSequence.php:207
Commercetools\Base\MapperSequence\at
at(int $index)
Definition
MapperSequence.php:117
Commercetools\Base\MapperSequence\jsonSerialize
jsonSerialize()
Definition
MapperSequence.php:46
Commercetools\Base\MapperSequence\valid
valid()
Definition
MapperSequence.php:199
Commercetools\Base\MapperSequence\index
index($data)
Definition
MapperSequence.php:64
Commercetools\Base\MapperSequence\offsetUnset
offsetUnset($offset)
Definition
MapperSequence.php:246
Commercetools\Base\MapperSequence\end
end()
Definition
MapperSequence.php:168
Commercetools\Base\MapperSequence\key
key()
Definition
MapperSequence.php:190
Commercetools\Base\MapperSequence\of
static of()
Definition
MapperSequence.php:258
Commercetools\Base\MapperSequence\getIterator
getIterator()
Definition
MapperSequence.php:143
Commercetools\Base\MapperSequence\toArray
toArray()
Definition
MapperSequence.php:40
Commercetools\Base\MapperSequence\addToIndex
addToIndex(string $field, string $key, int $index)
Definition
MapperSequence.php:130
Commercetools\Base\MapperSequence\__construct
__construct(array $data=null)
Definition
MapperSequence.php:31
Commercetools\Base\MapperSequence\current
current()
Definition
MapperSequence.php:159
Commercetools\Base\MapperSequence\mapper
mapper()
Commercetools\Base\MapperSequence\offsetExists
offsetExists($offset)
Definition
MapperSequence.php:216
Commercetools\Base\MapperSequence\valueByKey
valueByKey(string $field, string $key)
Definition
MapperSequence.php:138
Commercetools\Base\MapperSequence\next
next()
Definition
MapperSequence.php:182
Commercetools\Base\CSequence
Definition
CSequence.php:19
Commercetools\Base
Definition
MapperArraySequence.php:10
Generated by
1.9.8