Merge pull request #9188 from simonberger/fix-php53-closure-self-usage
Fix self usage in closures results in fatal error on PHP 5.3pull/9197/head
commit
c6d0309d48
|
@ -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']);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue