1 | <?php |
||
10 | final class ItemList |
||
11 | { |
||
12 | /** |
||
13 | * |
||
14 | */ |
||
15 | private CONST STATE_NONE = 0; |
||
16 | /** |
||
17 | * |
||
18 | */ |
||
19 | private CONST STATE_NAME = 1; |
||
20 | /** |
||
21 | * |
||
22 | */ |
||
23 | private CONST STATE_SECTION = 2; |
||
24 | /** |
||
25 | * |
||
26 | */ |
||
27 | private CONST STATE_PARTIAL = 3; |
||
28 | /** |
||
29 | * |
||
30 | */ |
||
31 | private CONST STATE_OCTET = 4; |
||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $list = []; |
||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $size; |
||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $body; |
||
44 | |||
45 | /** |
||
46 | * ItemList constructor. |
||
47 | * @param array $list |
||
48 | */ |
||
49 | 22 | public function __construct(array $list = []) |
|
53 | |||
54 | /** |
||
55 | * @param ItemInterface $item |
||
56 | * @return ItemList |
||
57 | */ |
||
58 | 17 | public function withItem(ItemInterface $item): self |
|
64 | |||
65 | /** |
||
66 | * @param int $size |
||
67 | * @return ItemList |
||
68 | */ |
||
69 | 6 | public function withOctet(int $size): self |
|
75 | |||
76 | /** |
||
77 | * @param string $body |
||
78 | * @return ItemList |
||
79 | */ |
||
80 | 5 | public function withBody(string $body): self |
|
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | public function getBody(): string |
|
94 | |||
95 | /** |
||
96 | * @param string $name |
||
97 | * @return ItemInterface |
||
98 | */ |
||
99 | 5 | public function getItem(string $name): ItemInterface |
|
100 | { |
||
101 | 5 | if (!isset($this->list[$name])) { |
|
102 | 1 | throw new \UnexpectedValueException( |
|
103 | 1 | sprintf('Unknown name %s', $name) |
|
104 | ); |
||
105 | } |
||
106 | |||
107 | 4 | return $this->list[$name]; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @return ItemInterface |
||
112 | */ |
||
113 | 6 | public function last(): ItemInterface |
|
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | */ |
||
125 | 6 | public function __toString(): string |
|
151 | |||
152 | /** |
||
153 | * @param string $serializedList |
||
154 | * @return ItemList |
||
155 | */ |
||
156 | 13 | public static function fromString(string $serializedList): self |
|
265 | } |