Passed
Push — master ( f11089...634c17 )
by Aimeos
04:11
created

Base::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2024
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Common\Catalog\Import\Csv\Processor;
12
13
14
/**
15
 * Abstract class with common methods for all CSV import processors
16
 *
17
 * @package Controller
18
 * @subpackage Common
19
 */
20
class Base
21
	extends \Aimeos\Controller\Jobs\Common\Catalog\Import\Csv\Base
22
{
23
	use \Aimeos\Controller\Jobs\Common\Types;
24
25
26
	private \Aimeos\Controller\Jobs\Common\Catalog\Import\Csv\Processor\Iface $object;
27
	private \Aimeos\MShop\ContextIface $context;
28
	private array $mapping;
29
30
31
	/**
32
	 * Initializes the object
33
	 *
34
	 * @param \Aimeos\MShop\ContextIface $context Context object
35
	 * @param array $mapping Associative list of field position in CSV as key and domain item key as value
36
	 * @param \Aimeos\Controller\Jobs\Common\Catalog\Import\Csv\Processor\Iface $object Decorated processor
37
	 */
38
	public function __construct( \Aimeos\MShop\ContextIface $context, array $mapping,
39
		\Aimeos\Controller\Jobs\Common\Catalog\Import\Csv\Processor\Iface $object = null )
40
	{
41
		$this->context = $context;
42
		$this->mapping = $mapping;
43
		$this->object = $object;
44
	}
45
46
47
	/**
48
	 * Stores all types for which no type items exist yet
49
	 */
50
	public function finish()
51
	{
52
		if( $this->object ) {
53
			$this->object->finish();
54
		}
55
56
		$this->saveTypes();
57
	}
58
59
60
	/**
61
	 * Returns the context item
62
	 *
63
	 * @return \Aimeos\MShop\ContextIface Context object
64
	 */
65
	protected function context() : \Aimeos\MShop\ContextIface
66
	{
67
		return $this->context;
68
	}
69
70
71
	/**
72
	 * Returns the mapping list
73
	 *
74
	 * @return array Associative list of field positions in CSV as keys and domain item keys as values
75
	 */
76
	protected function getMapping() : array
77
	{
78
		return $this->mapping;
79
	}
80
81
82
	/**
83
	 * Returns the decorated processor object
84
	 *
85
	 * @return \Aimeos\Controller\Jobs\Common\Catalog\Import\Csv\Processor\Iface Processor object
86
	 * @throws \Aimeos\Controller\Jobs\Exception If no processor object is available
87
	 */
88
	protected function object() : Iface
89
	{
90
		if( $this->object === null ) {
91
			throw new \Aimeos\Controller\Jobs\Exception( 'No processor object available' );
92
		}
93
94
		return $this->object;
95
	}
96
}
97