LegacyCollectionDecoderAggregate.php
979 Bytes
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
<?php
namespace ACP\Storage\ListScreen;
use LogicException;
class LegacyCollectionDecoderAggregate implements LegacyCollectionDecoder {
/**
* @var LegacyCollectionDecoder[]
*/
private $collection_decoders = [];
public function __construct( array $collection_decoders ) {
array_map( [ $this, 'add' ], $collection_decoders );
}
private function add( LegacyCollectionDecoder $collection_decoder ) {
$this->collection_decoders[] = $collection_decoder;
}
public function decode( array $data ) {
foreach ( $this->collection_decoders as $collection_decoder ) {
if ( $collection_decoder->can_decode( $data ) ) {
return $collection_decoder->decode( $data );
}
}
throw new LogicException( 'Unable to decode ListScreen collection.' );
}
public function can_decode( array $data ) {
foreach ( $this->collection_decoders as $collection_decoder ) {
if ( $collection_decoder->can_decode( $data ) ) {
return true;
}
}
return false;
}
}