Skip to content

Commit ce0c3a3

Browse files
author
Eduard Muradov
committed
Release 1.1.4
1 parent c3c0f4e commit ce0c3a3

File tree

4 files changed

+89
-6
lines changed

4 files changed

+89
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Amasty\ImportExportCore\Block\Adminhtml\System\Config;
5+
6+
use Amasty\ImportExportCore\Utils\CliPhpResolver;
7+
use Magento\Framework\Data\Form\Element\AbstractElement;
8+
use Magento\Framework\UrlInterface;
9+
use Magento\Config\Block\System\Config\Form\Field;
10+
use Magento\Backend\Block\Template\Context;
11+
12+
class CliPhpPath extends Field
13+
{
14+
/**
15+
* @var CliPhpResolver
16+
*/
17+
private $cliPhpResolver;
18+
19+
public function __construct(
20+
Context $context,
21+
CliPhpResolver $cliPhpResolver
22+
) {
23+
parent::__construct($context);
24+
$this->cliPhpResolver = $cliPhpResolver;
25+
}
26+
27+
public function render(AbstractElement $element)
28+
{
29+
try {
30+
$phpPath = $this->cliPhpResolver->getExecutablePath();
31+
} catch (\Exception $e) {
32+
$phpPath = '';
33+
}
34+
$element->setText($phpPath);
35+
36+
return parent::render($element);
37+
}
38+
}

Utils/CliPhpResolver.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
namespace Amasty\ImportExportCore\Utils;
66

7+
use Magento\Framework\App\Config\ScopeConfigInterface;
78
use Magento\Framework\App\DeploymentConfig;
89
use Magento\Framework\Shell;
910
use Symfony\Component\Process\PhpExecutableFinder;
1011

1112
class CliPhpResolver
1213
{
13-
private const PHP_EXECUTABLE_PATH = 'php_executable_path';
14+
private const ENV_PHP_EXECUTABLE_PATH = 'php_executable_path';
15+
private const CONFIG_PHP_EXECUTABLE_PATH = 'amasty_base/system/cli_php_path';
1416

1517
private const VERSION_CHECK_REGEXP = '/PHP [\d\.\+a-z-]+ \(cli\)/';
1618

@@ -29,19 +31,26 @@ class CliPhpResolver
2931
*/
3032
private $shell;
3133

34+
/**
35+
* @var ScopeConfigInterface
36+
*/
37+
private $configProvider;
38+
3239
/**
3340
* @var string
3441
*/
3542
private $executablePath;
3643

3744
public function __construct(
3845
DeploymentConfig $deploymentConfig,
46+
ScopeConfigInterface $configProvider,
3947
PhpExecutableFinder $executableFinder,
4048
Shell $shell
4149
) {
4250
$this->deploymentConfig = $deploymentConfig;
4351
$this->executableFinder = $executableFinder;
4452
$this->shell = $shell;
53+
$this->configProvider = $configProvider;
4554
}
4655

4756
/**
@@ -62,7 +71,8 @@ public function getExecutablePath(): string
6271
private function resolvePhpExecutable()
6372
{
6473
$pathCandidates = [
65-
$this->deploymentConfig->get(self::PHP_EXECUTABLE_PATH),
74+
$this->configProvider->getValue(self::CONFIG_PHP_EXECUTABLE_PATH),
75+
$this->deploymentConfig->get(self::ENV_PHP_EXECUTABLE_PATH),
6676
$this->executableFinder->find()
6777
];
6878

Utils/OptionsProcessor.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Amasty\ImportExportCore\Utils;
6+
7+
class OptionsProcessor
8+
{
9+
public function process(array $options, bool $allowValueIsArray = true): array
10+
{
11+
$preparedOptions = [];
12+
13+
foreach ($options as $option) {
14+
if (!is_array($option)) {
15+
continue;
16+
}
17+
18+
if ($this->isValid($option, $allowValueIsArray)) {
19+
$option['value'] = !is_array($option['value'])
20+
? (string)$option['value']
21+
: $option['value'];
22+
23+
$preparedOptions[] = $option;
24+
} else {
25+
array_push($preparedOptions, ...$this->process($option));
26+
}
27+
}
28+
29+
return $preparedOptions;
30+
}
31+
32+
private function isValid(array $option, bool $allowValueIsArray): bool
33+
{
34+
return isset($option['value'])
35+
&& ($allowValueIsArray || !is_array($option['value']));
36+
}
37+
}

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
"php": ">=7.3"
66
},
77
"type": "magento2-module",
8-
"version": "1.1.3",
9-
"license": [
10-
"Commercial"
11-
],
8+
"version": "1.1.4",
9+
"license": "proprietary",
1210
"autoload": {
1311
"files": [
1412
"registration.php"

0 commit comments

Comments
 (0)