ResponseFactory.php
837 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
43
44
45
46
<?php
namespace ACP\Migrate\Export;
use AC\ListScreenCollection;
use ACP\Migrate\Export\Response\File;
use ACP\Storage\ListScreen\Encoder;
use ACP\Storage\ListScreen\SerializerTypes;
use LogicException;
final class ResponseFactory {
const FILE = 'file';
/**
* @var Encoder
*/
private $encoder;
public function __construct( Encoder $encoder ) {
$this->encoder = $encoder;
}
/**
* @param ListScreenCollection $list_screens
* @param string|null $type
*
* @return Response
*/
public function create( ListScreenCollection $list_screens, $type = null ) {
if ( null === $type ) {
$type = self::FILE;
}
if ( $type === self::FILE ) {
return new File(
SerializerTypes::JSON,
$list_screens,
$this->encoder
);
}
throw new LogicException( 'Invalid response type found.' );
}
}