FileFactory.php
1.7 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace ACP\ListScreenRepository;
use AC\ListScreenRepository\Rules;
use AC\ListScreenRepository\Storage;
use ACP\ListScreenRepository;
use ACP\Storage\AbstractDecoderFactory;
use ACP\Storage\Directory;
use ACP\Storage\EncoderFactory;
use ACP\Storage\Serializer;
use InvalidArgumentException;
final class FileFactory implements Storage\ListScreenRepositoryFactory
{
private $encoder_factory;
private $decoder_factory;
private $serializer;
private $i18n_serializer_factory;
public function __construct(
EncoderFactory $encoder_factory,
AbstractDecoderFactory $decoder_factory,
Serializer\PhpSerializer\File $serializer,
Serializer\PhpSerializer\I18nFactory $i18n_serializer_factory
) {
$this->encoder_factory = $encoder_factory;
$this->decoder_factory = $decoder_factory;
$this->serializer = $serializer;
$this->i18n_serializer_factory = $i18n_serializer_factory;
}
public function create(
string $path,
bool $writable,
Rules $rules = null,
string $i18n_text_domain = null
): Storage\ListScreenRepository {
if ($path === '') {
throw new InvalidArgumentException('Invalid path.');
}
$serializer = $this->serializer;
if ($i18n_text_domain) {
$serializer = $this->i18n_serializer_factory->create($serializer, $i18n_text_domain);
}
$file = new ListScreenRepository\File(
new Directory($path),
$this->encoder_factory,
$this->decoder_factory,
$serializer
);
return new Storage\ListScreenRepository($file, $writable, $rules);
}
}