Symfoy2HttpKernel event-driven, symfoy2httpkernel. Symfoy2HttpKernel: Event-driven Symfony2 framework layer and application layer are all completed in the HttpKernel: handle () method, HttpKernel: ha Symfoy2 HttpKernel event-driven, symfoy2httpkernel
HttpKernel: Event-drivenThe Symfony2 framework layer and application layer work in the HttpKernel: handle () method, HttpKernel: handle () the internal implementation is actually done by scheduling events (the event listener in HttpKernel), which is equivalent to integrating all components into a complete application. It is easy to use HttpKernel. you only need to create an EventDispatcher and controller resolver to implement more application functions of event listeners: kernel. requestEvent implementation kernel. the purpose of the request event is to add more information to the Request object or get the returned Response object (for example, get from the cache or reject access by the security layer) kernel. the request event is the first event scheduled by HttpKernel: handle (). Multiple listeners listening to the event will be executed. Event listeners are diverse and their behavior is different. for example, when the security listener judges that the user does not have sufficient permissions, a RedirectResponse object is returned, then the kernel is directly executed. response event: the purpose of the event is either to directly create and return the Response object, or to add more information to the Request object.
RouterListener is the kernel implemented in the Symfony framework. the most important listener of the request event. the RouterListener is executed in the routing layer and returns an array containing route information that meets the current request, for example, the _ controller and the request parameters ({name}) in the routing matching mode }). These information will be stored in the attributes array in the Request. Currently, only route information will be added to the Request object without any other actions, but will be used when parsing the Controller.
2) Resolve the Controller assumes that the Response object is not created and returned when the kernel. request event is implemented, the next step is to determine and parse the parameters required by the controller and controller. The controller part is the last bastion of the application layer. it is responsible for creating and returning the Response object containing a specific page. How to determine the requested controller depends entirely on the application. this task is completed by the controller parser-a class that implements ControllerResolverInterface and a parameter of the HttpKernel constructor. Call the getController () method of controller resolver and pass in the Request object to the method. the controller resolver determines based on the information contained in the Request and returns the controller. The second method, getArguments () will be executed when the kernel. controller event is scheduled.
Resolution ControllerThe Symfony framework uses the built-in ControllerResolver (essentially a subclass with additional functions). The parser uses RouterListener to save the attributes attribute information of the Request object to determine the controller. GetControllerControllerResolverIn the attributes array of the Request objectThe lookup _ controller key (the information is actually stored in the Request object by RouterListener ): A) if_ Controller keyThe value in the format of AcmeDemoBundle: Default: index. The value contains the class name and method name, which can be parsed by the Symfony framework. for example:Acme \ DemoBundle \ Controller \ defacontroller Controller: indexAction, which is converted by the specific Symfony framework.The child class of ControllerResolver. B) your controller class will be instantiated, and the controller class must contain a constructor without parameters. C) If your controller implements ContainerAwareInterface, the setContainer method will be called and the container will be injected into the controller,This implementation is also specific to the Symfony framework.The child class of ControllerResolver. There are also some other changes above, for example, you configure your controller as a service.
3)
kernel.controller
Event
The kernel. controller event initializes some information or changes the controller object before the controller is executed.
After the called controller is determined, the HttpKernel: handle () will schedule the kernel. controller event. After a certain part of the system is determined (for example, controller and route information) but these parts are executed, the listener that listens to the kernel. controller event will run.
4) obtain the controller parametersThe getAttributes () method returns an array of parameters that will be passed to the controller. you can also customize this method or use the built-in Symfony framework. ControllerResolver uses the radiation mechanism to obtain the parameter list of the called controller method. Traverse the list and use the following steps to determine a pair of values in the parameter list:
A) use the parameter as the key to find the attributes array in the Request object. if it is found, the corresponding value will be passed into the controller method. for example, the first parameter of the controller method is $ name, the attributes array of the Request contains $Value of attributes ['name '],$Attributes ['name'] will be used.
B) If this parameter is specified when Symfony configures routing, the search for this parameter will be skipped.
5) Call controller
In this step, the controller will be executed. The controller creates a Response object that contains a specific page or json, which is the last step of the application layer.
In the Symfony framework, there is no default listener to implement the kernel. view event. However, there is a core Bundle -- SensioFrameworkExtraBundle that listens for the change event listener. If your controller returns an array with @ Template annotation at the top of the controller class, the listener will render a Template and pass the array returned by the controller into the Template, finally, create a Response object using the Content returned by the template and return the Response object.
In addition, FOSRestBundle also monitors the event, a listener on this event which aims to give you a robust view layer capable of using a single controller to return each different content-type responses (e.g. HTML, JSON, XML, etc ).
7) kernel. response event
Modify the Response object before sending it to the client. The objective of kernel is to convert the Request object into a Response object. The Response object may be created in the kernel. request event, which may be returned by the controller or by the listener listening to the kernel. view event. No matter at which stage the Response object is created, the final kernel. response event will be triggered. The listener listening to the kernel. response event will modify the Response object in some way, for example, modifying the header part of the Response, modifying the cookie, or even modifying the content returned by the Response object (injecting javascriptAfter the kernel. response event is complete, HttpKernel: handle () returns the final Response object, and calls the Response: send () box client to send headers and Response entities.
Implement the kernel. response event in the Symfony framework The Symfony framework has several built-in listeners to listen to kernel. response events. more can be obtained through the developer community. For example, in the dev development environment, WebDebugToolbarListener injects javascript code into the bottom of the page, and the debug toolbar is displayed. Another listener, ContextListener, serializes the information of the current user and saves it to the session. the next request directly reloads the user information in the session.
8) kernel. terminate event
Listeners that listen to this event are usually used to process time-consuming background programs. The last event of the HttpKernel process is the kernel. terminate event. The event is triggered after the HttpKernel: handle () method, and the response content has been sent to the user. A complete workflow of the Symfony frameworkWhen using the HttpKernel component, we do not need to add any listeners to the kernel events or implement controller resolver. The listener and controller resolver provided by the HTTp component can work normally: Sub-requestsIn addition to passing "main request" to HttpKernel: handle, you can also pass the so-called "sub request" to HttpKernel: handle. The subrequest looks similar to other requests. The difference is that a general request renders a complete page, and a subrequest renders a part of a page. Generally, we create a subrequest in the controller (or in the template ). When the HttpKernel: handle method runs a subrequest, you need to modify the value of the second parameter: the subrequest also creates a complete request-response cycle. The only difference is that some listeners may only run (security) in "main request ). The subclass of KernelEvent is passed to the listener. the listener uses KernelEvent: getRequestType () to determine whether the current request is "main request" or "sub request ". For example, a listener will only execute in the request of "main request:
What is the difference between the kernel of linux24 and linux26? Is there some driver? Is there any hardware driver in it? For example, USB
You don't know that these are not your mistakes. if you are wrong, you always want to wait for others to give you the ready-made information. Search for the answer by yourself !~ Then you can grow up. Don't waste any time asking these meaningless questions.
Lenovo G450, a new version of win81, drivers installed in life, often auto restart phenomenon, check the event is kernel-power
Dear Lenovo user!
This is caused by missing or incomplete files or conflicts with other software.
We recommend that you go to the official website to download the video card driver. link:
Support1.lenovo.com.cn/lenovo/wsi/Modules/Drive.aspx
We recommend that you first uninstall the driver on the control panel-Device Manager before uninstalling the driver, and then press F8 to enter safe mode for installation.
If it is invalid, you can try win + r, enter msconfig, and close the startup item to troubleshoot conflicting software programs.
Or enter cmd and enter sfc/scannow at the command prompt to repair the system file.
The problem persists. we recommend that you reinstall the system.
For more information, see
Idea Forum: lenovobbs.lenovo.com.cn/...ureply
Think Forum: thinkbbs.lenovo.com.cn/...ureply
Lenovo community: bbs.lenovomobile.com/...ureply
We look forward to your satisfaction. thank you for your support for Lenovo and wish you a happy life!
Lenovo enterprise platform [official certification]
Http://www.bkjia.com/PHPjc/897400.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/897400.htmlTechArticleSymfoy2 HttpKernel event-driven, symfoy2httpkernel HttpKernel: Event-driven Symfony2 framework layer and application layer work is completed in the HttpKernel: handle () method, HttpKernel: ha...