Completed
Push — 15.x ( 1a7f4e...53b7d0 )
by Tim
65:00 queued 61:58
created

ExportableTrait::export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Plugins\ExportableTrait
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Plugins;
22
23
use TechDivision\Import\Adapter\ExportAdapterInterface;
24
25
/**
26
 * The trait implementation for the artefact export functionality.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import
32
 * @link      http://www.techdivision.com
33
 */
34
trait ExportableTrait
35
{
36
37
    /**
38
     * The export adapter instance.
39
     *
40
     * @var \TechDivision\Import\Adapter\ExportAdapterInterface
41
     */
42
    protected $exportAdapter;
43
44
    /**
45
     * Return's the artefacts for post-processing.
46
     *
47
     * @return array The artefacts
48
     */
49
    abstract public function getArtefacts();
50
51
    /**
52
     * Return's the target directory for the artefact export.
53
     *
54
     * @return string The target directory for the artefact export
55
     */
56
    abstract public function getTargetDir();
57
58
    /**
59
     * Reset the array with the artefacts to free the memory.
60
     *
61
     * @return void
62
     */
63
    abstract public function resetArtefacts();
64
65
    /**
66
     * Export's the artefacts to CSV files and resets the array with the artefacts to free the memory.
67
     *
68
     * @param integer $timestamp The timestamp part of the original import file
69
     * @param string  $counter   The counter part of the origin import file
70
     *
71
     * @return void
72
     */
73
    public function export($timestamp, $counter)
74
    {
75
76
        // export the artefacts
77
        $this->getExportAdapter()->export($this->getArtefacts(), $this->getTargetDir(), $timestamp, $counter);
78
79
        // reset the artefacts
80
        $this->resetArtefacts();
81
    }
82
83
    /**
84
     * Set's the exporter adapter instance.
85
     *
86
     * @param \TechDivision\Import\Adapter\ExportAdapterInterface $exportAdapter The exporter adapter instance
87
     *
88
     * @return void
89
     */
90
    public function setExportAdapter(ExportAdapterInterface $exportAdapter)
91
    {
92
        $this->exportAdapter = $exportAdapter;
93
    }
94
95
    /**
96
     * Return's the exporter adapter instance.
97
     *
98
     * @return \TechDivision\Import\Adapter\ExportAdapterInterface The exporter adapter instance
99
     */
100
    public function getExportAdapter()
101
    {
102
        return $this->exportAdapter;
103
    }
104
}
105