了解 ZF2 事件系统:
Understanding ZF2 event system:
如 Enrico Zimuel 的教程“MVC + Events + Modules: the new architecture of ZF2”所示,基本的 ZF2 MVC 事件结构如下所示:
ZF MVC Auth 扩展并添加了基本的 MVC 流程,向其中添加了四个事件(EVENT_AUTHENTICATION
、EVENT_AUTHENTICATION_POST
、EVENT_AUTHORIZATION
、EVENT_AUTHORIZATION_POST
)。
现在我正在阅读 Apigility“Advanced Authentication and Authorization”文档,上面写着:
In order to achieve integration to the ZF2 MVC lifecycle for authentication, zf-mvc-auth
wires in 4 listeners that then propagate their own events. Each of these listeners are registered within the event MvcEvent::EVENT_ROUTE
at different priorities.
有两点我不清楚:
"Each of these listeners are registered within the event MvcEvent::EVENT_ROUTE
" -- "Nested events"?这是什么意思?
"within the event MvcEvent::EVENT_ROUTE
at different priorities" -- 事件优先级层次结构"nested"/不直线?是多维的吗?
您可以将侦听器 附加到 或 on 事件;这些听众将按他们的优先级排序。
当事件被触发时(比如事件 MvcEvent::EVENT_ROUTE
),注册的侦听器将一个接一个地执行,从具有最高优先级的侦听器开始到最低优先级。
"Nested events" 或 "propagate their own events" 将是其中一个侦听器 触发 另一个事件的地方。一个例子是 the listener for rendering, \Zend\View\Http\DefaultRenderingStrategy::render()
,其中 MvcEvent::EVENT_RENDER_ERROR
在发生渲染错误时被触发。
如 Enrico Zimuel 的教程“MVC + Events + Modules: the new architecture of ZF2”所示,基本的 ZF2 MVC 事件结构如下所示:
ZF MVC Auth 扩展并添加了基本的 MVC 流程,向其中添加了四个事件(EVENT_AUTHENTICATION
、EVENT_AUTHENTICATION_POST
、EVENT_AUTHORIZATION
、EVENT_AUTHORIZATION_POST
)。
现在我正在阅读 Apigility“Advanced Authentication and Authorization”文档,上面写着:
In order to achieve integration to the ZF2 MVC lifecycle for authentication,
zf-mvc-auth
wires in 4 listeners that then propagate their own events. Each of these listeners are registered within the eventMvcEvent::EVENT_ROUTE
at different priorities.
有两点我不清楚:
"Each of these listeners are registered within the event
MvcEvent::EVENT_ROUTE
" -- "Nested events"?这是什么意思?"within the event
MvcEvent::EVENT_ROUTE
at different priorities" -- 事件优先级层次结构"nested"/不直线?是多维的吗?
您可以将侦听器 附加到 或 on 事件;这些听众将按他们的优先级排序。
当事件被触发时(比如事件 MvcEvent::EVENT_ROUTE
),注册的侦听器将一个接一个地执行,从具有最高优先级的侦听器开始到最低优先级。
"Nested events" 或 "propagate their own events" 将是其中一个侦听器 触发 另一个事件的地方。一个例子是 the listener for rendering, \Zend\View\Http\DefaultRenderingStrategy::render()
,其中 MvcEvent::EVENT_RENDER_ERROR
在发生渲染错误时被触发。