src/vendor/symfony/src/Symfony
applications directory, we will see three directories:Framework
directory, which contains:Framework/DoctrineBundle
: this is Doctrine ORMFramework/ProfilerBundle
: this is a friend of the developer - toolbarFramework/SwiftmailerBundle
: Swift mailerFramework/WebBundle
: web, templating, userFramework/ZendBundle
: Zend library, now used by Zend_LogFoundation
content is similar to the core code library, i.e. it contains code that allows this miracle to work as it should. In particular, the base class of the kernel, the kernel “bundle”, EventDispatcher, the universal class autoloader, the abstract Bundle class that implements the BundleInterface interface, from which all the “bundles” are not followed.Components
- these are the components , but written in the style of PHP 5.3. Currently available:web/index.php
controller, an instance of the application's kernel class is created in our case, HelloKernel
, which extends the Symfony\Foundation\Kernel
class. When creating an object, two parameters are passed to the class constructor: the name of the environment and the debug flag enable true or false. The class constructor invokes the methods for registering bundles, registering search paths for bundles, registering the application root directory, and determining the name of the application itself. After that, in the front controller, the run()
method is called in which the main work takes place. And again, briefly, the main work looks like this: the boot()
method is executed in which the DI container is initialized (Dependency Injection Container), the methods for constructing the container of all connected “bundles” are called during initialization. After that, the method of loading the application settings is called. Then this entire constructed and formed container is written to the cache as a class, in order not to build it with each request, a file from the cache is connected and an instance of this generated container class is created.boot()
method of all connected "bundles" is called. Then the request object is pulled out of the container, by default it is an object of the class Symfony\Components\RequestHandler\Request
. And then the request handler object is pulled out of the container, by default it is an object of the Symfony\Components\RequestHandler\RequestHandler
, from which the handle()
method is called and as a parameter it receives the already received request object. The handle()
method must return a Symfony\Components\RequestHandler\Response
response object, which in turn calls the send()
method, which is responsible for sending the response (headers and bodies). Now, if it is short and rough, then the work of the kernel is limited to this. Everything else lies on the shoulders of "bundles."Symfony\Foundation\BundleInterface
in which only two methods are buildContainer(ContainerInterface $container)
registering parameters and services in the container and boot(ContainerInterface $container)
which is responsible for loading the bundle, loading is already done after all the parameters and services of all the “bundles” are defined in the DI container. Most “bundles”, namely all “bundles” from Symfony/Framework
extend the Symfony\Foundation\Bundle
class and overlap only the builderContainer
method to define their settings and services in the container.boot()
method of the class Bundle
. By default, Webbundle's “bundle” uses a template engine based on Symfony\Components\Templating
. But the templating.engine
service in the WebBundle is defined in such a way that it does not allow you to transfer your Renderer classes to the constructor, while Symfony\Components\Templating\Engine
in the constructor takes the second Renderer array as a second parameter. But thanks to the use of Dependency Injection Container, this slight misunderstanding is easily fixed. To do this, in our application, in the src/Application/HelloBundle/Bundle.php
file in the Bundle
class, we define the method:public function boot (ContainerInterface $ container) { $ container-> getTemplatingService () -> setRenderer ('name', new Renderer ()); }
Renderer
class is our custom renderer, and 'name'
name of this renderer. Now, when displaying templates, you can use your own renderer.Components/Console
. Another interesting feature has appeared - the symfony shell. It is enough to run hello/console -s
and an interactive console session starts, to put it more simply, a symfony shell allows you to execute the same commands.Source: https://habr.com/ru/post/89157/
All Articles