Welcome Guest, Not a member yet? Register   Sign In
isCLI method broken - I think it is a bug..
#1

(This post was last modified: 07-06-2022, 05:39 AM by yahyaerturan.)

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..
Reply
#2

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

(This post was last modified: 03-06-2023, 07:50 AM by jobyjosephme.)

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.
Reply
#4

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB