Skip to content

Commit f4d53f7

Browse files
author
Eduard Muradov
committed
Initial commit
0 parents  commit f4d53f7

30 files changed

+2883
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Amasty\ImportExportCore\Api\Config\ConfigClass;
4+
5+
interface ArgumentInterface
6+
{
7+
/**
8+
* @return string
9+
*/
10+
public function getName();
11+
12+
/**
13+
* @param string $name
14+
*
15+
* @return void
16+
*/
17+
public function setName($name);
18+
19+
/**
20+
* @return string
21+
*/
22+
public function getType();
23+
24+
/**
25+
* @param string $type
26+
*
27+
* @return void
28+
*/
29+
public function setType($type);
30+
31+
/**
32+
* @return string
33+
*/
34+
public function getValue();
35+
36+
/**
37+
* @param string $value
38+
*
39+
* @return void
40+
*/
41+
public function setValue($value);
42+
43+
/**
44+
* @return \Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface[]
45+
*/
46+
public function getItems();
47+
48+
/**
49+
* @param \Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface[] $items
50+
*
51+
* @return void
52+
*/
53+
public function setItems($items);
54+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Amasty\ImportExportCore\Api\Config\ConfigClass;
4+
5+
interface ConfigClassInterface
6+
{
7+
/**
8+
* @return string
9+
*/
10+
public function getName(): string;
11+
12+
/**
13+
* @return \Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface[]
14+
*/
15+
public function getArguments(): ?array;
16+
}

Config/ConfigClass/Argument.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Amasty\ImportExportCore\Config\ConfigClass;
6+
7+
use Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface;
8+
use Magento\Framework\DataObject;
9+
10+
class Argument extends DataObject implements ArgumentInterface
11+
{
12+
public const NAME = 'name';
13+
public const VALUE = 'value';
14+
public const TYPE = 'type';
15+
public const ITEMS = 'items';
16+
17+
public function getName()
18+
{
19+
return $this->getData(self::NAME);
20+
}
21+
22+
public function setName($name)
23+
{
24+
$this->setData(self::NAME, $name);
25+
}
26+
27+
public function getType()
28+
{
29+
return $this->getData(self::TYPE);
30+
}
31+
32+
public function setType($type)
33+
{
34+
$this->setData(self::TYPE, $type);
35+
}
36+
37+
public function getValue()
38+
{
39+
return $this->getData(self::VALUE);
40+
}
41+
42+
public function setValue($value)
43+
{
44+
$this->setData(self::VALUE, $value);
45+
}
46+
47+
public function getItems()
48+
{
49+
return $this->getData(self::ITEMS);
50+
}
51+
52+
public function setItems($items)
53+
{
54+
$this->setData(self::ITEMS, $items);
55+
}
56+
}

Config/ConfigClass/ConfigClass.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Amasty\ImportExportCore\Config\ConfigClass;
6+
7+
use Amasty\ImportExportCore\Api\Config\ConfigClass\ConfigClassInterface;
8+
9+
class ConfigClass implements ConfigClassInterface
10+
{
11+
/**
12+
* @var string
13+
*/
14+
private $name;
15+
16+
/**
17+
* @var array
18+
*/
19+
private $arguments = [];
20+
21+
public function __construct(
22+
string $name,
23+
?string $baseType = '',
24+
?array $arguments = []
25+
) {
26+
if (!empty($baseType) && !is_subclass_of($name, $baseType)) {
27+
throw new \LogicException(
28+
'Class ' . $name . ' doesn\'t implement ' . $baseType
29+
);
30+
}
31+
32+
$this->name = $name;
33+
$this->arguments = $arguments;
34+
}
35+
36+
public function getName(): string
37+
{
38+
return $this->name;
39+
}
40+
41+
public function getArguments(): ?array
42+
{
43+
return $this->arguments;
44+
}
45+
}

Config/ConfigClass/Factory.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Amasty\ImportExportCore\Config\ConfigClass;
6+
7+
use Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface;
8+
use Amasty\ImportExportCore\Api\Config\ConfigClass\ConfigClassInterface;
9+
use Magento\Framework\Data\Argument\InterpreterInterface;
10+
use Magento\Framework\ObjectManagerInterface;
11+
12+
class Factory
13+
{
14+
/**
15+
* @var ObjectManagerInterface
16+
*/
17+
private $objectManager;
18+
19+
/**
20+
* @var InterpreterInterface
21+
*/
22+
private $argumentInterpreter;
23+
24+
public function __construct(
25+
ObjectManagerInterface $objectManager,
26+
InterpreterInterface $argumentInterpreter
27+
) {
28+
$this->objectManager = $objectManager;
29+
$this->argumentInterpreter = $argumentInterpreter;
30+
}
31+
32+
/**
33+
* Creates instance based on specified config class
34+
*
35+
* @param ConfigClassInterface $configClass
36+
* @return mixed
37+
*/
38+
public function createObject(ConfigClassInterface $configClass)
39+
{
40+
return $this->objectManager->create(
41+
$configClass->getName(),
42+
[
43+
'config' => $this->prepareArguments(
44+
$this->convertArguments($configClass->getArguments())
45+
)
46+
]
47+
);
48+
}
49+
50+
private function prepareArguments(array $arguments): array
51+
{
52+
$result = [];
53+
foreach ($arguments as $key => $argument) {
54+
$result[$key] = $this->argumentInterpreter->evaluate($argument);
55+
}
56+
57+
return $result;
58+
}
59+
60+
/**
61+
* @param ArgumentInterface[] $arguments
62+
* @return array
63+
*/
64+
private function convertArguments(array $arguments): array
65+
{
66+
$result = [];
67+
foreach ($arguments as $argument) {
68+
$argName = $argument->getName();
69+
$argType = $argument->getType();
70+
71+
$row = [
72+
'name' => $argName,
73+
'xsi:type' => $argType
74+
];
75+
if ($argType === 'array') {
76+
$row['item'] = $this->convertArguments($argument->getItems());
77+
} else {
78+
$row['value'] = $argument->getValue();
79+
}
80+
81+
$result[$argName] = $row;
82+
}
83+
84+
return $result;
85+
}
86+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Amasty\ImportExportCore\Config\SchemaReader\ConfigCompiler;
6+
7+
use Magento\Framework\Exception\LocalizedException;
8+
use Magento\Framework\Module\Dir;
9+
10+
class IncludeElement extends \Magento\Config\Model\Config\Compiler\IncludeElement
11+
{
12+
protected function getContent($includePath)
13+
{
14+
list($moduleName, $filename) = explode('::', $includePath);
15+
16+
$directoryRead = $this->readFactory->create(
17+
$this->moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, $moduleName)
18+
);
19+
20+
if ($directoryRead->isExist($filename) && $directoryRead->isFile($filename)) {
21+
return $directoryRead->readFile($filename);
22+
}
23+
24+
throw new LocalizedException(__('The file "%1" does not exist', $filename));
25+
}
26+
}

0 commit comments

Comments
 (0)