George Irimiciuc
George Irimiciuc

Reputation: 4633

Where is Symfony's Kernel handle() function called?

I am trying to understand how Symfony works, so I'm taking a look on its internals. In app.php I have something like this:

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';  
require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();    

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

What interests me is the handle() function. AppKernel extends Kernel, which implements KernelInterface. The handle() function is implemented in Kernel and not in AppKernel. AppKernel just registers the bundles and the config file(s). The function is as follows:

   public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
    {
        if (false === $this->booted) {
            $this->boot();
        }

        return $this->getHttpKernel()->handle($request, $type, $catch);
    }

That means that if I modify this function to do something, that should happen on any request. For instance, typing exit; at the beginning of the function should break the application. However, my application works like nothing happens. Am I looking at the wrong function or what is wrong?

I've also cleared the cache many times, and tried both prod and dev environment but without success.

EDIT

It seems that it has to do with the bootstrap.php.cache file. If I change it toautoload.php instead, it works. The problem is that with removing it I get:

Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in E:\svn\medapp\app\AppKernel.php on line 8

What's the issue here? How can I run an app that doesn't depend on the autoloader?

Upvotes: 2

Views: 2263

Answers (1)

Frank B
Frank B

Reputation: 3697

Symfony uses the spl_autoload_register() function to automatically load every class that is needed. It makes all the require_once rules unnecessary while only the classes are loaded that we need. I found this spl_autoload_register in bootstrap.php.cache so it seems that if you skip this file from loading that you also killed the autoloading process.

Upvotes: 1

Related Questions