Yaf_Dispatcher::registerPlugin
(Since Yaf 1.0.0.5)
例 11.28. Yaf_Dispatcher::registerPlugin
的例子
<?php /** * 所有在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用, * 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher * 调用的次序, 和申明的次序相同 */ class Bootstrap extends Yaf_Bootstrap_Abstract{ /** * 注册一个插件 * 插件的目录是在application_directory/plugins */ public function _initPlugin(Yaf_Dispatcher $dispatcher) { $user = new UserPlugin(); $dispatcher->registerPlugin($user); } } /** * 插件类定义 * UserPlugin.php */ class UserPlugin extends Yaf_Plugin_Abstract { public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { echo "Plugin routerStartup called <br/>\n"; } public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { echo "Plugin routerShutdown called <br/>\n"; } public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { echo "Plugin DispatchLoopStartup called <br/>\n"; } public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { echo "Plugin PreDispatch called <br/>\n"; } public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { echo "Plugin postDispatch called <br/>\n"; } public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { echo "Plugin DispatchLoopShutdown called <br/>\n"; } }