1 | <?php |
||
23 | abstract class AbstractDTOCollection implements DTOCollection, \IteratorAggregate |
||
24 | { |
||
25 | use ImmutabilityBehaviour, PayloadBehaviour { |
||
26 | PayloadBehaviour::__call insteadof ImmutabilityBehaviour; |
||
27 | __call as private payloadCall; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * DTOCollection constructor. |
||
32 | * |
||
33 | * @param array<string, mixed> $elements |
||
34 | */ |
||
35 | final protected function __construct(array $elements) |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | final public static function fromElements(array $elements): DTOCollection |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function getElements(): \Traversable |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | final public function getIterator(): \Traversable |
||
67 | |||
68 | /** |
||
69 | * Verify collection elements type. |
||
70 | * |
||
71 | * @param mixed[] $elements |
||
72 | * |
||
73 | * @throws InvalidCollectionTypeException |
||
74 | * @throws InvalidParameterException |
||
75 | */ |
||
76 | private function verifyElementsType(array $elements): void |
||
101 | |||
102 | /** |
||
103 | * Transform collection elements for output. |
||
104 | * |
||
105 | * @param mixed[] $elements |
||
106 | * |
||
107 | * @return \Traversable |
||
108 | */ |
||
109 | final protected function outputElements(array $elements): \Traversable |
||
113 | |||
114 | /** |
||
115 | * Get allowed DTO type for collection elements. |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | abstract protected function getAllowedType(): string; |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | * |
||
124 | * @return string[] |
||
125 | */ |
||
126 | final protected function getAllowedInterfaces(): array |
||
130 | } |
||
131 |