Skip to content

Commit 2fa236c

Browse files
authored
Merge pull request #5836 from kenjis/fix-spark-options-php74
fix: spark can't use options on PHP 7.4
2 parents 94cc0fe + d0b323d commit 2fa236c

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

system/CLI/CommandRunner.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,14 @@ public function __construct()
4040
* so we have the chance to look for a Command first.
4141
*
4242
* @param string $method
43-
* @param array ...$params
43+
* @param array $params
4444
*
4545
* @throws ReflectionException
4646
*
4747
* @return mixed
4848
*/
49-
public function _remap($method, ...$params)
49+
public function _remap($method, $params)
5050
{
51-
// The first param is usually empty, so scrap it.
52-
if (empty($params[0])) {
53-
array_shift($params);
54-
}
55-
5651
return $this->index($params);
5752
}
5853

system/CodeIgniter.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,14 +884,16 @@ protected function runController($class)
884884
/** @var CLIRequest $request */
885885
$request = $this->request;
886886
$params = $request->getArgs();
887+
888+
$output = $class->_remap($this->method, $params);
887889
} else {
888890
// This is a Web request or PHP CLI request
889891
$params = $this->router->params();
890-
}
891892

892-
$output = method_exists($class, '_remap')
893-
? $class->_remap($this->method, ...$params)
894-
: $class->{$this->method}(...$params);
893+
$output = method_exists($class, '_remap')
894+
? $class->_remap($this->method, ...$params)
895+
: $class->{$this->method}(...$params);
896+
}
895897

896898
$this->benchmark->stop('controller');
897899

tests/system/CLI/CommandRunnerTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,4 @@ public function testBadCommand()
117117
// make sure the result looks like a command list
118118
$this->assertStringContainsString('Command "bogus" not found', CITestStreamFilter::$buffer);
119119
}
120-
121-
/**
122-
* @TODO When the first param is empty? Use case?
123-
*/
124-
public function testRemapEmptyFirstParams()
125-
{
126-
self::$runner->_remap('anyvalue', null, 'list');
127-
$result = CITestStreamFilter::$buffer;
128-
129-
// make sure the result looks like a command list
130-
$this->assertStringContainsString('Lists the available commands.', $result);
131-
}
132120
}

tests/system/SparkTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace CodeIgniter;
13+
14+
use CodeIgniter\Test\CIUnitTestCase;
15+
16+
/**
17+
* @internal
18+
*/
19+
final class SparkTest extends CIUnitTestCase
20+
{
21+
public function testCanUseOption()
22+
{
23+
ob_start();
24+
passthru('php spark list --simple');
25+
$output = ob_get_clean();
26+
27+
$this->assertStringContainsString('cache:clear', $output);
28+
}
29+
}

user_guide_src/source/changelogs/v4.2.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ BREAKING
1616
- The ``CodeIgniter\CodeIgniter`` class has a new property ``$context`` and it must have the correct context at runtime. So the following files have been changed:
1717
- ``public/index.php``
1818
- ``spark``
19+
- The method signature of ``CodeIgniter\CLI\CommandRunner::_remap()`` has been changed to fix a bug.
1920

2021
Enhancements
2122
************

0 commit comments

Comments
 (0)