-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathData.php
More file actions
executable file
·109 lines (99 loc) · 2.64 KB
/
Data.php
File metadata and controls
executable file
·109 lines (99 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Firebear\ImportExport\Helper;
use Firebear\ImportExport\Model\Source\Factory;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Serialize\SerializerInterface;
/**
* Class Data
* @package Firebear\ImportExport\Helper
*/
class Data extends AbstractHelper
{
const GENERAL_DEBUG = 'firebear_importexport/general/debug';
/**
* @var ScopeConfigInterface
*/
protected $coreConfig;
/**
* Import source type factory model
*
* @var Factory
*/
protected $sourceFactory;
/**
* Json Serializer
*
* @var SerializerInterface
*/
public $serializer;
/**
* Data Helper constructor
*
* @param Context $context
* @param Factory $sourceFactory
* @param SerializerInterface $serializer
*/
public function __construct(
Context $context,
Factory $sourceFactory,
SerializerInterface $serializer
) {
$this->coreConfig = $context->getScopeConfig();
$this->sourceFactory = $sourceFactory;
$this->serializer = $serializer;
parent::__construct($context);
}
/**
* Prepare source type class name
*
* @param string $sourceType
*
* @return string
*/
protected function prepareSourceClassName($sourceType)
{
return 'Firebear\ImportExport\Model\Source\Type\\' . ucfirst(strtolower($sourceType));
}
/**
* Get source model by source type
*
* @param string $sourceType
*
* @return \Firebear\ImportExport\Model\Source\Type\AbstractType
* @throws LocalizedException
*/
public function getSourceModelByType($sourceType)
{
$sourceClassName = $this->prepareSourceClassName($sourceType);
if ($sourceClassName && class_exists($sourceClassName)) {
/* @var $source \Firebear\ImportExport\Model\Source\Type\AbstractType */
$source = $this->getSourceFactory()->create($sourceClassName);
return $source;
} else {
throw new LocalizedException(
__("Import source type class for '" . $sourceType . "' is not exist.")
);
}
}
/**
* Get source factory
*
* @return Factory
*/
public function getSourceFactory()
{
return $this->sourceFactory;
}
/**
* @return bool
*/
public function getDebugMode()
{
return (bool)$this->coreConfig->getValue(
self::GENERAL_DEBUG,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
}