Welcome Guest, Not a member yet? Register   Sign In
[5.0] Loading the core framework
#1

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__;
const 
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';

$app->run(\CodeIgniter\ConsoleKernel::class);


# ROOT/public/index.php

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

$app->run(\CodeIgniter\HTTP\RequestHandler::class); 

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)));
    }
}

class 
CodeIngiter
{
    public function __construct()
    {
        Services::exceptions()->initialize($this);
    }

    public function run($handler)
    {
        $response = (new $handler)->handle();
        $this->sendResponse($response);
    }

    protected function sendResponse(ResponseInterface $response)
    {
        $response->send();
    }


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:
ob_start();
$this->codeigniter->run();
ob_get_clean();
$response $this->getPrivateProperty($this->codeigniter'response'); 
and also make it possible for developers to change the handler.
Reply
#2

I agree to rework the flow.

Here is the 4.3 flow for my understanding:
http://blog.a-way-out.net/img/2022/10/31...s-flow.svg
Reply
#3

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

Here is the 4.3 flow for my understanding:
http://blog.a-way-out.net/img/2022/10/31...s-flow.svg

Isn't this the current architecture?

What is the difference?
Reply
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB