Skip to content

Commit 02222f9

Browse files
authored
MAGECLOUD-5127: Update Constraints for Magento 2.4 (#19)
1 parent 7eb8f4a commit 02222f9

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
"php": "^7.0",
99
"ext-json": "*",
1010
"composer/composer": "@stable",
11+
"composer/semver": "^1.5",
1112
"symfony/config": "^3.3||^4.3",
1213
"symfony/console": "^2.6||^4.0",
1314
"symfony/dependency-injection": "^3.3||^4.3",
1415
"symfony/process": "^2.1||^4.1"
1516
},
16-
"conflict": {
17-
"symfony/process": "^4.2"
18-
},
1917
"require-dev": {
2018
"phpmd/phpmd": "@stable",
2119
"phpunit/phpunit": "^6.2",

config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
<service id="Magento\CloudPatches\Command\Patch\ManagerException" autowire="false"/>
1414
<service id="Magento\CloudPatches\Patch\ApplierException" autowire="false"/>
1515
<service id="Magento\CloudPatches\Filesystem\FileNotFoundException" autowire="false"/>
16+
<service id="Magento\CloudPatches\Shell\PackageNotFoundException" autowire="false"/>
1617
</services>
1718
</container>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CloudPatches\Shell;
9+
10+
use Magento\CloudPatches\App\GenericException;
11+
12+
/**
13+
* Exception if a Composer package could not be found for some reason (e.g., symfony/process).
14+
*/
15+
class PackageNotFoundException extends GenericException
16+
{
17+
}

src/Shell/ProcessFactory.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace Magento\CloudPatches\Shell;
99

10+
use Composer\Composer;
11+
use Composer\Repository\RepositoryInterface;
12+
use Composer\Semver\Comparator;
1013
use Magento\CloudPatches\Filesystem\DirectoryList;
1114
use Symfony\Component\Process\Process;
1215

@@ -17,17 +20,25 @@
1720
*/
1821
class ProcessFactory
1922
{
23+
const ARRAY_PARAM_MIN_VERSION = '3.3.0';
24+
2025
/**
2126
* @var DirectoryList
2227
*/
2328
private $directoryList;
2429

30+
/**
31+
* @var RepositoryInterface
32+
*/
33+
private $repository;
34+
2535
/**
2636
* @param DirectoryList $directoryList
2737
*/
28-
public function __construct(DirectoryList $directoryList)
38+
public function __construct(DirectoryList $directoryList, Composer $composer)
2939
{
3040
$this->directoryList = $directoryList;
41+
$this->repository = $composer->getLocker()->getLockedRepository();
3142
}
3243

3344
/**
@@ -37,8 +48,22 @@ public function __construct(DirectoryList $directoryList)
3748
public function create(array $cmd): Process
3849
{
3950
return new Process(
40-
implode(' ', $cmd),
51+
$this->processSupportsArrayParam() ? $cmd : implode(' ', $cmd),
4152
$this->directoryList->getMagentoRoot()
4253
);
4354
}
55+
56+
/**
57+
* Test if symfony/process is current enough to support an array for its first parameter.
58+
*/
59+
private function processSupportsArrayParam(): bool
60+
{
61+
$package = $this->repository->findPackage('symfony/process', '*');
62+
63+
if ($package === null) {
64+
throw new PackageNotFoundException('Could not find symfony/process package.');
65+
}
66+
67+
return Comparator::greaterThanOrEqualTo($package->getVersion(), self::ARRAY_PARAM_MIN_VERSION);
68+
}
4469
}

0 commit comments

Comments
 (0)