Skip to content

Commit 4c8a131

Browse files
committed
Allow new and old Symfony Process versions.
Required for us because Composer uses an old one, but Magento uses a new one.
1 parent b2da266 commit 4c8a131

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jamescowie/composer-patcher",
33
"description": "Apply patches using composer",
44
"license": "MIT",
5-
"version": "1.0.6",
5+
"version": "1.0.7",
66
"authors": [
77
{
88
"name": "jamescowie",

src/Inviqa/Patch/Patch.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ final public function apply()
5757
protected function doApply()
5858
{
5959
$patchPath = escapeshellarg($this->fileInfo->getRealPath());
60-
$process = Process::fromShellCommandline("patch -p 1 < $patchPath");
60+
$process = $this->fromShellCommandline("patch -p 1 < $patchPath");
6161
$process->mustRun();
6262
return $process->getExitCode() === 0;
6363
}
@@ -68,7 +68,7 @@ protected function doApply()
6868
protected function canApply()
6969
{
7070
$patchPath = escapeshellarg($this->fileInfo->getRealPath());
71-
$process = Process::fromShellCommandline("patch --dry-run -p 1 < $patchPath");
71+
$process = $this->fromShellCommandline("patch --dry-run -p 1 < $patchPath");
7272
try {
7373
$process->mustRun();
7474
return $process->getExitCode() === 0;
@@ -85,7 +85,7 @@ protected function canApply()
8585
protected function isApplied()
8686
{
8787
$patchPath = escapeshellarg($this->fileInfo->getRealPath());
88-
$process = Process::fromShellCommandline("patch --dry-run -p 1 -R < $patchPath");
88+
$process = $this->fromShellCommandline("patch --dry-run -p 1 -R < $patchPath");
8989
try {
9090
$process->mustRun();
9191
$result = $process->getExitCode() === 0;
@@ -101,6 +101,20 @@ protected function isApplied()
101101
}
102102
}
103103

104+
/**
105+
* @process string $cmd Command to execute.
106+
* @return Process
107+
*/
108+
protected function fromShellCommandline($cmd)
109+
{
110+
// Newer Symfony/Process versions use Process::fromShellCommandline().
111+
// We have to support both because Composer uses an ancient one bundled in the phar.
112+
if (is_callable([Process::class, 'fromShellCommandline'])) {
113+
return Process::fromShellCommandline($cmd);
114+
}
115+
return new Process($cmd);
116+
}
117+
104118
/**
105119
* @return Output
106120
*/

test/Integration/Patch/PatcherTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ protected function tearDown()
3131
}
3232

3333
$patchPath = escapeshellarg($this->fileInfo->getRealPath());
34-
$process = Process::fromShellCommandline("patch -p 1 -R < $patchPath");
34+
if (is_callable([Process::class, 'fromShellCommandline'])) {
35+
$process = Process::fromShellCommandline("patch -p 1 -R < $patchPath");
36+
} else {
37+
$process = new Process("patch -p 1 -R < $patchPath");
38+
}
3539
$process->mustRun();
3640
}
3741

0 commit comments

Comments
 (0)