天天看點

Symfony學習--HttpKernel元件1 處理request2 解析controller3 處理controller4 擷取controller參數5 實際調用controller6 view7 kernel.response 事件8 kernel.terminate事件異常處理:

<a href="http://symfony.com/doc/2.1/components/http_kernel/introduction.html">http://symfony.com/doc/2.1/components/http_kernel/introduction.html</a>

httpkernel這個類提供的功能說白了就是将request轉換成response。它使用一個流程的工作流似的方式。

整個流程圖大緻如下:

Symfony學習--HttpKernel元件1 處理request2 解析controller3 處理controller4 擷取controller參數5 實際調用controller6 view7 kernel.response 事件8 kernel.terminate事件異常處理:

httpkernel最核心的是handle(); 它的工作就是将上圖的request轉換成response。

handle()是由事件驅動的,你可以建立一系列的事件監聽

典型的代碼如下:

Symfony學習--HttpKernel元件1 處理request2 解析controller3 處理controller4 擷取controller參數5 實際調用controller6 view7 kernel.response 事件8 kernel.terminate事件異常處理:

步驟:

一個request可以有多個listener,listener可能直接中斷,并且直接傳回response。

這裡有個controllerresolver類來對controller進行解析,它有兩個接口:

getcontroller

getarguments

如果你要自定義這個解析類,你就需要自己實作這兩個接口。

初始化,并且在實際執行前改變對應的控制器

通過getarguments()這個方法來擷取controller的參數

這個階段會實際調用controller了,并得到傳回的資料

這個階段就是mvc的view層。将controller中傳回的資料加上view層

在資料傳回前改變對應的response事件。

在資料傳回給使用者前處理一些較重的事件。

是觸發了kernel.exception事件

每個異常都傳回了一個getresponseforexceptionevent事件,你可以使用getexception()方法擷取原始的異常。