JsonFilesystemExporter::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Setup package.
5
 *
6
 * (c) Sitewards GmbH
7
 */
8
9
namespace Sitewards\Setup\Service\Page;
10
11
use JMS\Serializer\Serializer;
12
use Sitewards\Setup\Domain\Page\PageRepositoryInterface;
13
use Symfony\Component\Filesystem\Filesystem;
14
15
final class JsonFilesystemExporter implements ExporterInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    private $filename = 'pages.json';
21
22
    /**
23
     * @var PageRepositoryInterface
24
     */
25
    private $pageRepository;
26
27
    /**
28
     * @var Serializer
29
     */
30
    private $serializer;
31
32
    /**
33
     * @var Filesystem
34
     */
35
    private $filesystem;
36
37
    /**
38
     * @var array
39
     */
40
    private $identifier;
41
42
    /**
43
     * @param PageRepositoryInterface $pageRepository
44
     * @param Serializer $serializer
45
     * @param Filesystem $filesystem
46
     */
47
    public function __construct(
48
        PageRepositoryInterface $pageRepository,
49
        Serializer $serializer,
50
        Filesystem $filesystem
51
    )
52
    {
53
        $this->pageRepository = $pageRepository;
54
        $this->serializer     = $serializer;
55
        $this->filesystem     = $filesystem;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function setIdentifier(array $identifier = [])
62
    {
63
        $this->identifier = $identifier;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function execute()
70
    {
71
        $data = $this->pageRepository->find($this->identifier);
72
73
        $jsonContent = $this->serializer->serialize($data, 'json');
74
75
        $this->filesystem->dumpFile($this->filename, $jsonContent);
76
    }
77
}
78