Completed
Push — development ( f6174b...9d8e04 )
by Theodoros
09:35
created

FileExporter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 6
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Econda\Business\Exporter;
9
10
use Generated\Shared\Transfer\BatchResultTransfer;
11
use Generated\Shared\Transfer\FailedResultTransfer;
12
use Generated\Shared\Transfer\LocaleTransfer;
13
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator;
14
use SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class FileExporter extends AbstractExporter
18
{
19
20
    /**
21
     * @var \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\FileWriter
22
     */
23
    protected $writer;
24
25
    /**
26
     * @var \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator
27
     */
28
    protected $csvNameGenerator;
29
30
    /**
31
     * @var string
32
     */
33
    protected $exportPath;
34
35
    /**
36
     * FileExporter constructor.
37
     *
38
     * @param \SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface $writer
39
     * @param \Generated\Shared\Transfer\FailedResultTransfer $failedResultPrototype
40
     * @param \Generated\Shared\Transfer\BatchResultTransfer $batchResultTransferPrototype
41
     * @param \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator $csvNameGenerator
42
     * @param string $exportPath
43
     * @param array $collectorPlugins
44
     */
45
    public function __construct(
46
        WriterInterface $writer,
47
        FailedResultTransfer $failedResultPrototype,
48
        BatchResultTransfer $batchResultTransferPrototype,
49
        CsvNameGenerator $csvNameGenerator,
50
        $exportPath,
51
        array $collectorPlugins = []
52
    ) {
53
        parent::__construct(
54
            $writer,
55
            $failedResultPrototype,
56
            $batchResultTransferPrototype,
57
            $collectorPlugins
58
        );
59
60
        $this->csvNameGenerator = $csvNameGenerator;
61
        $this->exportPath = $exportPath;
62
    }
63
64
    /**
65
     * @param string $type
66
     * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer
67
     * @param \Symfony\Component\Console\Output\OutputInterface $output
68
     *
69
     * @return \Generated\Shared\Transfer\BatchResultTransfer
70
     */
71
    public function exportByType($type, LocaleTransfer $localeTransfer, OutputInterface $output)
72
    {
73
        $result = $this->getBatchResultTransfer();
74
        $result->setProcessedLocale($localeTransfer);
75
76
        if (!$this->isCollectorRegistered($type)) {
77
            $this->resetResult($result);
78
79
            return $result;
80
        }
81
82
        $fileName = $this->csvNameGenerator->generateFileName($type, $localeTransfer->getLocaleName());
83
        $this->writer->setFileName($fileName);
84
        $this->writer->setFolderPath($this->exportPath);
85
86
        $collectorPlugin = $this->collectorPlugins[$type];
87
        $collectorPlugin->run($localeTransfer, $result, $this->writer, $output);
88
89
        return $result;
90
    }
91
92
}
93