-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eduard Muradov
committed
May 20, 2022
0 parents
commit f4d53f7
Showing
30 changed files
with
2,883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Amasty\ImportExportCore\Api\Config\ConfigClass; | ||
|
||
interface ArgumentInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getName(); | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return void | ||
*/ | ||
public function setName($name); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(); | ||
|
||
/** | ||
* @param string $type | ||
* | ||
* @return void | ||
*/ | ||
public function setType($type); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue(); | ||
|
||
/** | ||
* @param string $value | ||
* | ||
* @return void | ||
*/ | ||
public function setValue($value); | ||
|
||
/** | ||
* @return \Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface[] | ||
*/ | ||
public function getItems(); | ||
|
||
/** | ||
* @param \Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface[] $items | ||
* | ||
* @return void | ||
*/ | ||
public function setItems($items); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Amasty\ImportExportCore\Api\Config\ConfigClass; | ||
|
||
interface ConfigClassInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string; | ||
|
||
/** | ||
* @return \Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface[] | ||
*/ | ||
public function getArguments(): ?array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Amasty\ImportExportCore\Config\ConfigClass; | ||
|
||
use Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface; | ||
use Magento\Framework\DataObject; | ||
|
||
class Argument extends DataObject implements ArgumentInterface | ||
{ | ||
public const NAME = 'name'; | ||
public const VALUE = 'value'; | ||
public const TYPE = 'type'; | ||
public const ITEMS = 'items'; | ||
|
||
public function getName() | ||
{ | ||
return $this->getData(self::NAME); | ||
} | ||
|
||
public function setName($name) | ||
{ | ||
$this->setData(self::NAME, $name); | ||
} | ||
|
||
public function getType() | ||
{ | ||
return $this->getData(self::TYPE); | ||
} | ||
|
||
public function setType($type) | ||
{ | ||
$this->setData(self::TYPE, $type); | ||
} | ||
|
||
public function getValue() | ||
{ | ||
return $this->getData(self::VALUE); | ||
} | ||
|
||
public function setValue($value) | ||
{ | ||
$this->setData(self::VALUE, $value); | ||
} | ||
|
||
public function getItems() | ||
{ | ||
return $this->getData(self::ITEMS); | ||
} | ||
|
||
public function setItems($items) | ||
{ | ||
$this->setData(self::ITEMS, $items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Amasty\ImportExportCore\Config\ConfigClass; | ||
|
||
use Amasty\ImportExportCore\Api\Config\ConfigClass\ConfigClassInterface; | ||
|
||
class ConfigClass implements ConfigClassInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $arguments = []; | ||
|
||
public function __construct( | ||
string $name, | ||
?string $baseType = '', | ||
?array $arguments = [] | ||
) { | ||
if (!empty($baseType) && !is_subclass_of($name, $baseType)) { | ||
throw new \LogicException( | ||
'Class ' . $name . ' doesn\'t implement ' . $baseType | ||
); | ||
} | ||
|
||
$this->name = $name; | ||
$this->arguments = $arguments; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getArguments(): ?array | ||
{ | ||
return $this->arguments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Amasty\ImportExportCore\Config\ConfigClass; | ||
|
||
use Amasty\ImportExportCore\Api\Config\ConfigClass\ArgumentInterface; | ||
use Amasty\ImportExportCore\Api\Config\ConfigClass\ConfigClassInterface; | ||
use Magento\Framework\Data\Argument\InterpreterInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
class Factory | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var InterpreterInterface | ||
*/ | ||
private $argumentInterpreter; | ||
|
||
public function __construct( | ||
ObjectManagerInterface $objectManager, | ||
InterpreterInterface $argumentInterpreter | ||
) { | ||
$this->objectManager = $objectManager; | ||
$this->argumentInterpreter = $argumentInterpreter; | ||
} | ||
|
||
/** | ||
* Creates instance based on specified config class | ||
* | ||
* @param ConfigClassInterface $configClass | ||
* @return mixed | ||
*/ | ||
public function createObject(ConfigClassInterface $configClass) | ||
{ | ||
return $this->objectManager->create( | ||
$configClass->getName(), | ||
[ | ||
'config' => $this->prepareArguments( | ||
$this->convertArguments($configClass->getArguments()) | ||
) | ||
] | ||
); | ||
} | ||
|
||
private function prepareArguments(array $arguments): array | ||
{ | ||
$result = []; | ||
foreach ($arguments as $key => $argument) { | ||
$result[$key] = $this->argumentInterpreter->evaluate($argument); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param ArgumentInterface[] $arguments | ||
* @return array | ||
*/ | ||
private function convertArguments(array $arguments): array | ||
{ | ||
$result = []; | ||
foreach ($arguments as $argument) { | ||
$argName = $argument->getName(); | ||
$argType = $argument->getType(); | ||
|
||
$row = [ | ||
'name' => $argName, | ||
'xsi:type' => $argType | ||
]; | ||
if ($argType === 'array') { | ||
$row['item'] = $this->convertArguments($argument->getItems()); | ||
} else { | ||
$row['value'] = $argument->getValue(); | ||
} | ||
|
||
$result[$argName] = $row; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Amasty\ImportExportCore\Config\SchemaReader\ConfigCompiler; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Module\Dir; | ||
|
||
class IncludeElement extends \Magento\Config\Model\Config\Compiler\IncludeElement | ||
{ | ||
protected function getContent($includePath) | ||
{ | ||
list($moduleName, $filename) = explode('::', $includePath); | ||
|
||
$directoryRead = $this->readFactory->create( | ||
$this->moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, $moduleName) | ||
); | ||
|
||
if ($directoryRead->isExist($filename) && $directoryRead->isFile($filename)) { | ||
return $directoryRead->readFile($filename); | ||
} | ||
|
||
throw new LocalizedException(__('The file "%1" does not exist', $filename)); | ||
} | ||
} |
Oops, something went wrong.