-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathKeyValueIterator.php
More file actions
42 lines (32 loc) · 822 Bytes
/
KeyValueIterator.php
File metadata and controls
42 lines (32 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace GT\Input\InputData;
use GT\Input\InputData\Datum\InputDatum;
trait KeyValueIterator {
/** @var int */
protected $iteratorKey;
public function current():?InputDatum {
return $this->parameters[$this->getIteratorDataKey()];
}
public function next():void {
$this->iteratorKey++;
}
public function key():string {
return $this->getIteratorDataKey();
}
public function valid():bool {
return !empty($this->getIteratorDataKey());
}
public function rewind():void {
$this->iteratorKey = 0;
}
protected function getIteratorDataKey():?string {
$keys = [];
if(is_array($this->parameters)) {
$keys = array_keys($this->parameters);
}
else if($this->parameters instanceof InputData) {
$keys = $this->parameters->getKeys();
}
return $keys[$this->iteratorKey] ?? null;
}
}