-
Notifications
You must be signed in to change notification settings - Fork 19
/
LabelIterator.php
46 lines (38 loc) · 954 Bytes
/
LabelIterator.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
<?php declare(strict_types=1);
namespace MpApiClient\Label\Entity;
use MpApiClient\Common\Util\AbstractStringKeyIterator;
/**
* @extends AbstractStringKeyIterator<Label>
* @property array<string, Label> $data
*/
final class LabelIterator extends AbstractStringKeyIterator
{
private function __construct(Label ...$data)
{
foreach ($data as $label) {
$this->data[$label->getId()] = $label;
}
}
/**
* @param array<int, array<string, mixed>> $data
*
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
...array_map(fn(array $item): Label => Label::createFromApi($item), $data)
);
}
/**
* @return false|Label
*/
public function current()
{
return current($this->data);
}
public function get(string $key): ?Label
{
return $this->data[$key] ?? null;
}
}