1 | <?php |
||
52 | abstract class AbstractMultipartHydrator extends AbstractHydrator |
||
53 | { |
||
54 | /** |
||
55 | * Subhydrators |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $subhydrators = array(); |
||
60 | /** |
||
61 | * Minimum occurrences |
||
62 | * |
||
63 | * @var int |
||
64 | */ |
||
65 | protected $minimumOccurrences = 1; |
||
66 | /** |
||
67 | * Maximum occurrences |
||
68 | * |
||
69 | * @var int |
||
70 | */ |
||
71 | protected $maximumOccurrences = 1; |
||
72 | /** |
||
73 | * Part aggregate class name |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $aggregateClass = null; |
||
78 | /** |
||
79 | * Empty occurrence dehydration behaviour |
||
80 | * |
||
81 | * @var string |
||
82 | */ |
||
83 | protected $occDhdrException = SkippedOccurrenceDehydrationException::class; |
||
84 | |||
85 | /** |
||
86 | * Multipart hydrator constructor |
||
87 | * |
||
88 | * @param array $subhydrators Subpart hydrators |
||
89 | * @param int $minOccurrences Minimum occurrences |
||
90 | * @param int $maxOccurrences Maximum occurrences |
||
91 | */ |
||
92 | 37 | public function __construct(array $subhydrators, $minOccurrences = 1, $maxOccurrences = 1) |
|
116 | |||
117 | /** |
||
118 | * Validate the parameters accepted by this hydrator |
||
119 | * |
||
120 | * By default, a multipart parameter accepts exactly two parameters: |
||
121 | * - the minimum number of occurrences of the contained part aggregate |
||
122 | * - the maximum number of occurrences of the contained part aggregate |
||
123 | * |
||
124 | * @param array $parameters Parameters |
||
125 | * @return boolean Parameters are valid |
||
126 | */ |
||
127 | 41 | public static function validateParameters(...$parameters) |
|
146 | |||
147 | /** |
||
148 | * Serialize a file part |
||
149 | * |
||
150 | * @param PartInterface $part File part |
||
151 | * @return string Serialized file part |
||
152 | * @throws InvalidArgumentException If the part class cannot be dehydrated by this hydrator |
||
153 | */ |
||
154 | 12 | public function dehydrate(PartInterface $part) |
|
184 | |||
185 | /******************************************************************************* |
||
186 | * STATIC METHODS |
||
187 | *******************************************************************************/ |
||
188 | |||
189 | /** |
||
190 | * Dehydrate a single occurrence |
||
191 | * |
||
192 | * @param array $occurrence Occurrence |
||
193 | * @return string Dehydrated occurrence |
||
194 | */ |
||
195 | abstract protected function dehydrateOccurrence(array $occurrence); |
||
196 | |||
197 | /******************************************************************************* |
||
198 | * PRIVATE METHODS |
||
199 | *******************************************************************************/ |
||
200 | |||
201 | /** |
||
202 | * Combine a list of dehydrated occurrences |
||
203 | * |
||
204 | * @param array $occurrences List of dehydrated occurrences |
||
205 | * @return string Combined dehydrated occurrences |
||
206 | */ |
||
207 | 4 | protected function combineDehydratedOccurrences(array $occurrences) |
|
211 | |||
212 | /** |
||
213 | * Initialize the aggregate part |
||
214 | * |
||
215 | * @param string $data Part data |
||
216 | * @return AbstractPartAggregate Part aggregate |
||
217 | */ |
||
218 | 33 | public function hydrate($data) |
|
243 | |||
244 | /** |
||
245 | * Dehydrate a single part with a particular subhydrator |
||
246 | * |
||
247 | * @param string $subhydrator Subhydrator name |
||
248 | * @param PartInterface $part Part instance |
||
249 | * @return string Dehydrated part |
||
250 | */ |
||
251 | 4 | protected function dehydratePart($subhydrator, PartInterface $part) |
|
257 | } |
||
258 |