Symfony的内核handle()函数在哪里调用?

时间:2021-07-08 18:12:44

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:

我试图了解Symfony是如何工作的,所以我正在研究它的内部结构。在app.php我有这样的事情:

$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:

我感兴趣的是handle()函数。 AppKernel扩展了Kernel,它实现了KernelInterface。 handle()函数在Kernel中实现,而不是在AppKernel中实现。 AppKernel只注册包和配置文件。功能如下:

   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?

这意味着如果我修改此函数来执行某些操作,那么应该在任何请求上发生。例如,输入exit;在函数的开头应该打破应用程序。但是,我的应用程序工作没有任何反应。我在看错了功能还是出了什么问题?

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

我也已多次清除缓存,并尝试了prod和dev环境但没有成功。

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:

它似乎与bootstrap.php.cache文件有关。如果我改为toautoload.php,它就可以了。问题是,删除它后,我得到:

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?

这有什么问题?如何运行不依赖于自动加载器的应用程序?

1 个解决方案

#1


1  

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.

Symfony使用spl_autoload_register()函数自动加载所需的每个类。它使得所有require_once规则都不必要,而只加载了我们需要的类。我在bootstrap.php.cache中找到了这个spl_autoload_register,所以看起来如果你从加载中跳过这个文件,你也杀了自动加载过程。

#1


1  

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.

Symfony使用spl_autoload_register()函数自动加载所需的每个类。它使得所有require_once规则都不必要,而只加载了我们需要的类。我在bootstrap.php.cache中找到了这个spl_autoload_register,所以看起来如果你从加载中跳过这个文件,你也杀了自动加载过程。