Home > Article > Backend Development > Symfoy2 HttpKernel event-driven, symfoy2httpkernel_PHP tutorial
<span>RouterListener是Symfony框架中实现</span>kernel.request<span>事件的最重要监听器,</span>RouterListener在路由层中执行,返回一个包含符合当前请求的路由信息的数组,例如路由匹配模式里面的_controller和请求的参数({name})。这些信息都会存放在Request里的attributes数组里面,目前只是会添加路由信息到Request对象中还没有做其它的动作,但是解析Controller的时候会被用到。
<span><em>解析Controller</em></span> <span><em>Symfony框架使用内置的ControllerResolver(实质上是使用了一个有额外的功能的子类),该解析器利用了RouterListener保存到Request对象的attributes属性里信息来确定controller。</em></span> <span><em> </em></span> <span><em>getController</em></span> <em>ControllerResolver </em><em>在Request对象的attributes数组中</em><em>查找 _controller 键(这些信息实际上是由RouterListener存放进Request对象中的):</em> <em> </em> <em>a) 如果</em><em><span><span>_controller 键对应</span></span></em><em><span>AcmeDemoBundle:Default:index 这个格式的值,那么该值就包含了类名和方法名,可以被Symfony框架解析成为,例如:</span></em><em><span>Acme\DemoBundle\Controller\DefaultController::indexAction,这个转换是由Symfony框架的特定的</span></em><em>ControllerResolver的子类完成的。</em> <em> </em> <em>b) 你的controller类会被实例化,而且该controller类必须包含一个无参的构造函数。</em> <em> </em> <span><em>c) 如果你的controller还实现了ContainerAwareInterface,那么setContainer方法就会被调用,container就会被注入到controller中,</em></span><em><span>这个实现也是由Symfony框架的特定的</span></em><em>ControllerResolver的子类完成的。</em> <em> </em> <em><span>上面也有一些其他变化过程,例如你把你的controller配置成为service。</span></em> <em><span> </span></em> <em> </em>
<code><code><code><span>kernel.controller</span>
kernel.controllerEvent The kernel.controller event is to initialize some information or change the controller object before the controller is executed.
After the called controller is determined, HttpKernel::handle() will dispatch the
<code><code><span> </span></code></code>
<span><em>a) 使用参数作为键查找Request对象中的attributes数组,如果找到,那么相应的值会传入到controller的方法中,例如:controller方法的第一个参数是$name,那么在Request的attributes数组中包含$</em></span><em>attributes['name']的值,那么</em><span><em>$</em></span><em>attributes['name']就会被使用。</em>
<em> </em>
<em>b) 如果该该参数在Symfony配置routing的时候被指定,那么就会跳过对该参数的查找。</em>
<em> </em>
5) Call controller
Symfony框架实现kernel.response事件 <em> </em> Symfony框架内置几个监听器监听kernel.response事件,更多的可以通过开发者社区获得。例如:在dev开发环境下WebDebugToolbarListener向页面的底部注入javascript代码,debug工具条就会显示出来。还有另一个监听器,ContextListener序列化当前用户的信息保存到session中,下一次请求的时候直接在session中重载用户信息。
8) kernel.terminate事件
The listener that listens to this event usually handles some time-consuming background programs. The last event of the HttpKernel process is the kernel.terminate event, and the event is triggered after the HttpKernel::handle() method, and the response content has been sent to the user. Symfony framework a complete workflow When using the HttpKernel component, we do not need to implement any listeners to add to kernel events, nor do we need to implement a controller resolver. The listener and controller resolver that come with the HTTP component can work normally: Sub-request In addition to passing the "main request" into HttpKernel::handle, you can also pass the so-called "sub request" into HttpKernel::handle. Subrequests look similar to other requests. The difference is that a general request renders a complete page, while a subrequest renders a part of a page. Usually we create a subrequest in the controller (or create it in the template). When the HttpKernel::handle method runs a subrequest, you need to modify the value of the second parameter: A subrequest also creates a complete request-response cycle. The only difference is that some listeners may only run in the "main request" (security). The subclass of KernelEvent is passed to the listener, and the listener determines whether the current request is "main request" or "sub request" through KernelEvent::getRequestType(). For example, a listener will only be executed under the request of "main request":
It’s not your fault that you don’t know this. Your fault is that you always want to wait for others to bring you ready-made things. Find out for yourself! ~Look slowly so you can grow. Stop wasting your time asking these pointless questions.
Dear Lenovo users!
This is caused by missing or incomplete files or conflicts with other software.
It is recommended that you download the graphics card driver from the official website, link:
support1.lenovo.com.cn/lenovo/wsi/Modules/Drive.aspx
It is recommended that you go to Control Panel - Device Manager before uninstalling Uninstall the corresponding driver, then boot up and press F8 to enter safe mode for installation.
If it doesn’t work, you can try win+r, enter msconfig, and close the startup items to troubleshoot conflicting software programs.
Or enter cmd and enter sfc/scannow at the command prompt to repair system files.
The problem is still not solved, it is recommended that you reinstall the system.
You can consult for more questions
idea forum: lenovobbs.lenovo.com.cn/...ureply
Think forum: thinkbbs.lenovo.com.cn/...ureply
Lenovo Music Community: bbs.lenovomobile.com/...ureply
Looking forward to your satisfactory evaluation, thank you for your support of Lenovo, and wish you a happy life!
Lenovo Enterprise Platform
[Official certification]