1
0
Fork 0

Merge pull request #9188 from simonberger/fix-php53-closure-self-usage

Fix self usage in closures results in fatal error on PHP 5.3
pull/9197/head
Jordi Boggiano 2020-09-08 12:12:59 +02:00 committed by GitHub
commit c6d0309d48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View File

@ -188,13 +188,13 @@ class HttpDownloader
$curl = $this->curl;
$canceler = function () use (&$job, $curl) {
if ($job['status'] === self::STATUS_QUEUED) {
$job['status'] = self::STATUS_ABORTED;
if ($job['status'] === HttpDownloader::STATUS_QUEUED) {
$job['status'] = HttpDownloader::STATUS_ABORTED;
}
if ($job['status'] !== self::STATUS_STARTED) {
if ($job['status'] !== HttpDownloader::STATUS_STARTED) {
return;
}
$job['status'] = self::STATUS_ABORTED;
$job['status'] = HttpDownloader::STATUS_ABORTED;
if (isset($job['curl_id'])) {
$curl->abortRequest($job['curl_id']);
}

View File

@ -158,13 +158,13 @@ class ProcessExecutor
$io = $this->io;
$canceler = function () use (&$job) {
if ($job['status'] === self::STATUS_QUEUED) {
$job['status'] = self::STATUS_ABORTED;
if ($job['status'] === ProcessExecutor::STATUS_QUEUED) {
$job['status'] = ProcessExecutor::STATUS_ABORTED;
}
if ($job['status'] !== self::STATUS_STARTED) {
if ($job['status'] !== ProcessExecutor::STATUS_STARTED) {
return;
}
$job['status'] = self::STATUS_ABORTED;
$job['status'] = ProcessExecutor::STATUS_ABORTED;
try {
if (defined('SIGINT')) {
$job['process']->signal(SIGINT);

View File

@ -16,6 +16,7 @@ use Composer\IO\ConsoleIO;
use Composer\Util\ProcessExecutor;
use Composer\Test\TestCase;
use Composer\IO\BufferIO;
use React\Promise\Promise;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
@ -113,4 +114,15 @@ class ProcessExecutorTest extends TestCase
$process->execute('php -r "echo \'<error>foo</error>\'.PHP_EOL;"');
$this->assertSame('<error>foo</error>'.PHP_EOL, $output->fetch());
}
public function testExecuteAsyncCancel()
{
$process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG));
$process->enableAsync();
/** @var Promise $promise */
$promise = $process->executeAsync('echo foo');
$this->assertEquals(1, $process->countActiveJobs());
$promise->cancel();
$this->assertEquals(0, $process->countActiveJobs());
}
}