Skip to content

Commit

Permalink
Release 1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard Muradov committed Sep 29, 2022
1 parent c3c0f4e commit ce0c3a3
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 6 deletions.
38 changes: 38 additions & 0 deletions Block/Adminhtml/System/Config/CliPhpPath.php
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);
}
}
14 changes: 12 additions & 2 deletions Utils/CliPhpResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace Amasty\ImportExportCore\Utils;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Shell;
use Symfony\Component\Process\PhpExecutableFinder;

class CliPhpResolver
{
private const PHP_EXECUTABLE_PATH = 'php_executable_path';
private const ENV_PHP_EXECUTABLE_PATH = 'php_executable_path';
private const CONFIG_PHP_EXECUTABLE_PATH = 'amasty_base/system/cli_php_path';

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

Expand All @@ -29,19 +31,26 @@ class CliPhpResolver
*/
private $shell;

/**
* @var ScopeConfigInterface
*/
private $configProvider;

/**
* @var string
*/
private $executablePath;

public function __construct(
DeploymentConfig $deploymentConfig,
ScopeConfigInterface $configProvider,
PhpExecutableFinder $executableFinder,
Shell $shell
) {
$this->deploymentConfig = $deploymentConfig;
$this->executableFinder = $executableFinder;
$this->shell = $shell;
$this->configProvider = $configProvider;
}

/**
Expand All @@ -62,7 +71,8 @@ public function getExecutablePath(): string
private function resolvePhpExecutable()
{
$pathCandidates = [
$this->deploymentConfig->get(self::PHP_EXECUTABLE_PATH),
$this->configProvider->getValue(self::CONFIG_PHP_EXECUTABLE_PATH),
$this->deploymentConfig->get(self::ENV_PHP_EXECUTABLE_PATH),
$this->executableFinder->find()
];

Expand Down
37 changes: 37 additions & 0 deletions Utils/OptionsProcessor.php
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']));
}
}
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
"php": ">=7.3"
},
"type": "magento2-module",
"version": "1.1.3",
"license": [
"Commercial"
],
"version": "1.1.4",
"license": "proprietary",
"autoload": {
"files": [
"registration.php"
Expand Down

0 comments on commit ce0c3a3

Please sign in to comment.