1 | <?php |
||
9 | class Template implements \Countable |
||
10 | { |
||
11 | /** |
||
12 | * @var TypeInterface[] |
||
13 | */ |
||
14 | private $template = []; |
||
15 | |||
16 | /** |
||
17 | * @param array $items |
||
18 | */ |
||
19 | 70 | public function __construct(array $items = []) |
|
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | * @see \Countable::count() |
||
29 | * @return int |
||
30 | */ |
||
31 | 56 | public function count(): int |
|
35 | |||
36 | /** |
||
37 | * Return an array of type serializers in the template |
||
38 | * |
||
39 | * @return Types\TypeInterface[] |
||
40 | */ |
||
41 | 60 | public function getItems(): array |
|
45 | |||
46 | /** |
||
47 | * Add a new TypeInterface to the Template |
||
48 | * |
||
49 | * @param TypeInterface $item |
||
50 | * @return Template |
||
51 | */ |
||
52 | 66 | public function addItem(TypeInterface $item): Template |
|
57 | |||
58 | /** |
||
59 | * Parse a sequence of objects from binary, using the current template. |
||
60 | * |
||
61 | * @param Parser $parser |
||
62 | * @return mixed[]|Buffer[]|int[]|string[] |
||
63 | */ |
||
64 | 6 | public function parse(Parser $parser): array |
|
77 | |||
78 | /** |
||
79 | * Write the array of $items to binary according to the template. They must |
||
80 | * each be an instance of Buffer or implement SerializableInterface. |
||
81 | * |
||
82 | * @param array $items |
||
83 | * @return BufferInterface |
||
84 | */ |
||
85 | 4 | public function write(array $items): BufferInterface |
|
100 | } |
||
101 |