-
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
Sep 29, 2022
1 parent
c3c0f4e
commit ce0c3a3
Showing
4 changed files
with
89 additions
and
6 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,38 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Amasty\ImportExportCore\Block\Adminhtml\System\Config; | ||
|
||
use Amasty\ImportExportCore\Utils\CliPhpResolver; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Backend\Block\Template\Context; | ||
|
||
class CliPhpPath extends Field | ||
{ | ||
/** | ||
* @var CliPhpResolver | ||
*/ | ||
private $cliPhpResolver; | ||
|
||
public function __construct( | ||
Context $context, | ||
CliPhpResolver $cliPhpResolver | ||
) { | ||
parent::__construct($context); | ||
$this->cliPhpResolver = $cliPhpResolver; | ||
} | ||
|
||
public function render(AbstractElement $element) | ||
{ | ||
try { | ||
$phpPath = $this->cliPhpResolver->getExecutablePath(); | ||
} catch (\Exception $e) { | ||
$phpPath = ''; | ||
} | ||
$element->setText($phpPath); | ||
|
||
return parent::render($element); | ||
} | ||
} |
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
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Amasty\ImportExportCore\Utils; | ||
|
||
class OptionsProcessor | ||
{ | ||
public function process(array $options, bool $allowValueIsArray = true): array | ||
{ | ||
$preparedOptions = []; | ||
|
||
foreach ($options as $option) { | ||
if (!is_array($option)) { | ||
continue; | ||
} | ||
|
||
if ($this->isValid($option, $allowValueIsArray)) { | ||
$option['value'] = !is_array($option['value']) | ||
? (string)$option['value'] | ||
: $option['value']; | ||
|
||
$preparedOptions[] = $option; | ||
} else { | ||
array_push($preparedOptions, ...$this->process($option)); | ||
} | ||
} | ||
|
||
return $preparedOptions; | ||
} | ||
|
||
private function isValid(array $option, bool $allowValueIsArray): bool | ||
{ | ||
return isset($option['value']) | ||
&& ($allowValueIsArray || !is_array($option['value'])); | ||
} | ||
} |
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