Symfony2 Kernel vs. HttpKernel

I am trying to follow this article:

http://fabien.potencier.org/article/62/create-your-own-framework-on-top-of-the-symfony2-components-part-12

Also look at HttpKernel https://github.com/symfony/HttpKernel

And I'm completely confused. It seems to me that the kernel is really much larger than the HttpKernel class, and even the standard Symfony app.php has

 $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); //$kernel = new AppCache($kernel); $request = Request::createFromGlobals(); $response = $kernel->handle($request); 

The kernel, in turn, will call HttpKernel->handle() inside $kernel->handle($request) ; plus seems to also take care of bundle loading?

However, when the kernel creates a service container via boot() inside handle() , it also compiles the container, making it impossible to add additional parameters and services.

So, I think my questions are:

  • Is there any specific reason that in the tutorial, the Framework class extends HttpKernel instead of the kernel?
  • Should I also follow this example? Or should I use Kernel as my kernel. And if so, how do I get around the compile() problem? I have options and services that I have to add, how do I handle?
+4
source share
1 answer

Kernel is the outermost shell of your application. It is used in full-screen Symfony mode to configure debugging and bundling modes, self-loading classes, and creating containers. Everything that is "global" for the application is configured here. It also wraps an instance of HttpKernel for convenience and delegates all calls to it.

HttpKernel manages the request / response life cycle. This is a separate class that dispatches events in the event manager. You change his behavior by adding listeners who respond to these events. So this is not an application at all. Configuration is a specific HttpKernel instance specific to your application.

Tell us about container compilation. The container is compiled. This compilation process applies some optimizations to it, and also adds some functionality (changing a container based on tags). After compiling it, it cannot be changed (modifications will violate these optimizations). When you have a compiled container, you can flush it to disk. Using PhpDumper , you can dump it into the generated PHP class, which is much more efficient than creating it every time.

Is there any specific reason that in the tutorial, the Framework class extends HttpKernel instead of the kernel?

Yes. The tutorial talks about how to create your own infrastructure with Symfony2 components. Kernel is the outer shell of the full-featured Symfony2 framework. If you use it, you are not using your own infrastructure. You are using the full symfony2 stack.

Should I also follow this example?

It depends. If you need Kernel stuff, you can just use the full symfony stack. But then you do not create your own infrastructure.

And if so, how do I get around the compilation problem ()? I have options and services that I have to add, how do I handle?

If you want a compiled container, you will need to add these parameters and services as extensions (packages allow you to bind extensions), and these extensions register services and parameters. This happens before the compilation stage, so the definitions can then be compiled and dumped to a file.

+9
source

Source: https://habr.com/ru/post/1440820/


All Articles