CodeIgniter Forums
[5.0] Loading the core framework - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Discussion (
+--- Thread: [5.0] Loading the core framework (/showthread.php?tid=84786)

[5.0] Loading the core framework - iRedds - 11-09-2022

I want you to consider the change in loading the core framework.
This change will optimize the code and give flexibility to developers who want to customize their handlers.
First of all I would suggest to move bootstrap.php to root and change as follows. (This will allow developers to make changes)

PHP Code:
# ROOT/bootstap.php

// Since the maintainers believe that the framework needs to be able to work without a composer,
// replacing "required" with "include" will not cause a missing autoloader file error.
include 'vendor/autoload.php';

// A console application may need to know the path to a public directory.
const ROOT __DIR__;
FCPATH ROOT '/public';
 Other path constants for the framework to work with.

// If there is no composer, then we manually include the framework core.
if (! class_exists(\CodeIgniter\CodeIgniter::class)) {
    require SYSTEMPATH 'CodeIgniter.php';

// In the constructor, we initiate the autoloader and all the necessary services for the framework to work.

return new \CodeIgniter\CodeIgniter(); 

And this is how the entry points for the console and HTTP requests might look like.

PHP Code:
# ROOT/spark.php

$app = require 'bootstrap.php';


# ROOT/public/index.php

$app = require '../bootstrap.php';


Looking at the core now, the Response::send() method can be called in different places than the code.

In the example above, the CodeIgniter::run() method for the HTTP request handler will expect an object of the Response class. And the core itself will call the Response::send() method in one place.

A simple example of what I mean.

PHP Code:
class Exceptions
    public function initialize(CodeIngiter $app)
        set_exception_handler(fn (...$params) => $app->sendResponse($this->exceptionHandler(...$params)));

    public function __construct()

    public function run($handler)
        $response = (new $handler)->handle();

    protected function sendResponse(ResponseInterface $response)

That is, both with a normal response and with exception handling. In both cases, CodeIgniter::sendResponse() will be called. This will give a single point of response that allowed you to hang events or any other logic.

Also, separating the request handler into a separate one will simplify testing (no need to read the buffer and extract the protected property),
PHP Code:
$response $this->getPrivateProperty($this->codeigniter'response'); 
and also make it possible for developers to change the handler.

RE: [5.0] Loading the core framework - kenjis - 11-11-2022

I agree to rework the flow.

Here is the 4.3 flow for my understanding:

RE: [5.0] Loading the core framework - iRedds - 11-15-2022

(11-11-2022, 12:20 AM)kenjis Wrote: I agree to rework the flow.

Here is the 4.3 flow for my understanding:

Isn't this the current architecture?

What is the difference?

RE: [5.0] Loading the core framework - kenjis - 11-15-2022

The mind map is for the current 4.3.
It is intended to help devs understand the current implementation.