forked from mallgroup/mpapi-client-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeItemIterator.php
56 lines (47 loc) · 1.17 KB
/
TreeItemIterator.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php declare(strict_types=1);
namespace MpApiClient\Category\Entity;
use MpApiClient\Common\Util\AbstractIntKeyIterator;
/**
* @extends AbstractIntKeyIterator<TreeItem>
* @property TreeItem[] $data
*/
final class TreeItemIterator extends AbstractIntKeyIterator
{
private function __construct(TreeItem ...$data)
{
$this->data = $data;
}
/**
* @param array<int, array<string, mixed>> $data
*
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
...array_map(fn(array $item): TreeItem => TreeItem::createFromApi($item), $data)
);
}
/**
* @param array<int, array<string, mixed>> $data
*
* @internal
*/
public static function createFromMixedApi(array $data): self
{
return new self(
...array_map(fn(array $item): TreeItem => TreeItem::createFromMixedApi($item), $data)
);
}
/**
* @return false|TreeItem
*/
public function current()
{
return current($this->data);
}
public function get(int $key): ?TreeItem
{
return $this->data[$key] ?? null;
}
}