CodeIgniter Forums
isCLI method broken - I think it is a bug.. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: isCLI method broken - I think it is a bug.. (/showthread.php?tid=82393)



isCLI method broken - I think it is a bug.. - yahyaerturan - 07-06-2022

Hi all,
In my app, I have extended IncomingRequest class and change overwrite request service to return my new extended class.
PHP Code:
<?php

namespace App\Libraries;

use 
CodeIgniter\HTTP\IncomingRequest as CI_IncomingRequest;
use 
CodeIgniter\HTTP\URI;
use 
CodeIgniter\HTTP\UserAgent;
use 
Config\Database;
use 
Config\Install;

class 
IncomingRequest extends CI_IncomingRequest
{
    public function __construct($configURI $uri null$body 'php://input'UserAgent $userAgent null)
    {
        parent::__construct($config$uri$body$userAgent);
        $this->getActiveLanguages();
    

Inside in getActiveLanguages() method;
PHP Code:
    if ($this->isCLI()) {
        // have code here for if cli
    } else {
        // have another code here if not cli
    
Before 4.2 update it was working fine. But now when I run php spark it falls into "NOT CLI" though it is definitely cli request.
What can I do? Is there a change here? Or it is a bug?

I have checked the Github.. In 4.2.0 some changes made IncomingRequest and CLIRequest files. After in 4.2.1 those changes are reverted back. Upgrading to 4.2.1 is the solution. Thanks..


RE: isCLI method broken - I think it is a bug.. - iRedds - 07-06-2022

1. For CLI, use Spark commands.
2. Why do you need a language in the CLI? It doesn't make any practical sense.


RE: isCLI method broken - I think it is a bug.. - jobyjosephme - 03-06-2023

why ci4 is overcomplicating things. why cant it be like ci3 and allow developers to use it like they wish. i felt ci4 is forcing developers to use only one way where ci3 allow much more freedom.


RE: isCLI method broken - I think it is a bug.. - kenjis - 03-06-2023

(03-06-2023, 07:50 AM)jobyjosephme Wrote: why ci4 is overcomplicating things. why cant it be like ci3 and allow developers to use it like they wish. i felt ci4 is forcing developers to use only one way where ci3 allow much more freedom.

The reason is complex.
1. CI4 tries to simplify things. CI4 provides Spark commands for CLI. Controllers are for Web, Spark commands are for CLI.
1. CI4 recommends better practices. Using Controllers via CLI is not good practice.
2. CI4's CLIRequest is a bit broken or having design flaw in my opinion. So if you believe a behavior is a bug, please report it on GitHub.