Skip to content

Commit 6707697

Browse files
committed
fix: PHP CLI request is not handled correctly
Spark request is instance of CLIRequest, but if I remove the `$this->request instanceof CLIRequest`, PHPStan outputs the error: ------ ------------------------------------------------------------------ Line system/CodeIgniter.php ------ ------------------------------------------------------------------ 830 Call to an undefined method CodeIgniter\HTTP\Request::getArgs(). ------ ------------------------------------------------------------------
1 parent 0e74b8d commit 6707697

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

system/CodeIgniter.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,14 +815,25 @@ protected function createController()
815815
*/
816816
protected function runController($class)
817817
{
818-
if ($this->request instanceof CLIRequest) {
819-
// This is a console request
818+
/*
819+
CI4 supports three types of requests:
820+
1. Web: URI segments become parameters, sent to Controllers via Routes,
821+
output controlled by Headers to browser
822+
2. Spark: accessed by CLI via the spark command, arguments are Command arguments,
823+
sent to Commands by CommandRunner, output controlled by CLI class
824+
3. PHP CLI: accessed by CLI via php public/index.php, arguments become URI segments,
825+
sent to Controllers via Routes, output varies
826+
*/
827+
828+
if (defined('SPARKED') && $this->request instanceof CLIRequest) {
829+
// This is a Spark request
820830
$params = $this->request->getArgs();
821831

822832
$output = method_exists($class, '_remap')
823833
? $class->_remap($this->method, $params)
824834
: $class->{$this->method}($params);
825835
} else {
836+
// This is a Web request or PHP CLI request
826837
$params = $this->router->params();
827838

828839
if (method_exists($class, '_remap')) {

0 commit comments

Comments
 (0)