|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019 |
|
6
|
|
|
* @package Controller |
|
7
|
|
|
* @subpackage Common |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Common\Common\Import\Xml; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Shared class for XML importers |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Common |
|
19
|
|
|
*/ |
|
20
|
|
|
trait Traits |
|
21
|
|
|
{ |
|
22
|
|
|
private $processors = []; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Returns the processor object for adding the product related information |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $type Type of the processor |
|
29
|
|
|
* @return \Aimeos\Controller\Common\Common\Import\Xml\Processor\Iface Processor object |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function getProcessor( $type ) |
|
32
|
|
|
{ |
|
33
|
|
|
if( !isset( $this->processors[$type] ) ) { |
|
34
|
|
|
$this->processors[$type] = $this->createProcessor( $type ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return $this->processors[$type]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Creates a new processor object of the given type |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $type Type of the processor |
|
45
|
|
|
* @return \Aimeos\Controller\Common\Common\Import\Xml\Processor\Iface Processor object |
|
46
|
|
|
* @throws \Aimeos\Controller\Common\Exception If type is invalid or processor isn't found |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function createProcessor( $type ) |
|
49
|
|
|
{ |
|
50
|
|
|
$context = $this->getContext(); |
|
|
|
|
|
|
51
|
|
|
$config = $context->getConfig(); |
|
52
|
|
|
|
|
53
|
|
|
if( ctype_alnum( $type ) === false ) |
|
54
|
|
|
{ |
|
55
|
|
|
$classname = is_string($type) ? '\\Aimeos\\Controller\\Common\\Common\\Import\\Xml\\Processor\\' . $type : '<not a string>'; |
|
|
|
|
|
|
56
|
|
|
throw new \Aimeos\Controller\Common\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$name = $config->get( 'controller/common/product/import/xml/processor/' . $type . '/name', 'Standard' ); |
|
60
|
|
|
|
|
61
|
|
|
if( ctype_alnum( $name ) === false ) |
|
62
|
|
|
{ |
|
63
|
|
|
$classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Common\\Import\\Xml\\Processor\\' . $type . '\\' . $name : '<not a string>'; |
|
64
|
|
|
throw new \Aimeos\Controller\Common\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$classname = '\\Aimeos\\Controller\\Common\\Common\\Import\\Xml\\Processor\\' . ucfirst( $type ) . '\\' . $name; |
|
68
|
|
|
|
|
69
|
|
|
if( class_exists( $classname ) === false ) { |
|
70
|
|
|
throw new \Aimeos\Controller\Common\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$iface = \Aimeos\Controller\Common\Common\Import\Xml\Processor\Iface::class; |
|
74
|
|
|
return \Aimeos\MW\Common\Base::checkClass( $iface, new $classname( $context ) ); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|