(Yaf >=1.0.0)
Plugins 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟缴地讹拷锟狡猴拷锟斤拷展锟斤拷锟�
锟斤拷锟�(Plugins)锟斤拷一锟斤拷锟洁。 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷浠� -- 锟斤拷锟斤拷锟斤拷锟揭ナ碉拷锟斤拷锟叫╋拷涌凇锟� 锟斤拷实锟斤拷锟较o拷锟矫诧拷锟�(Plugin)锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷唷�
一锟斤拷锟斤拷锟�(plugin)锟结被Yaf_Dispatcher::registerPlugin()锟斤拷锟截碉拷Yaf锟斤拷锟斤拷校锟� 锟节匡拷锟阶拷锟�(registerd)锟襟,诧拷锟�(plugin)锟斤拷锟叫讹拷锟藉方锟斤拷锟斤拷锟斤拷锟斤拷恰锟斤拷锟斤拷时锟戒被锟矫接匡拷执锟叫★拷
Example #1 Plugin example
<?php
/* bootstrap class should be defined under ./application/Bootstrap.php */
class Bootstrap extends Yaf_Bootstrap_Abstract {
public function _initPlugin(Yaf_Dispatcher $dispatcher) {
/* register a plugin */
$dispatcher->registerPlugin(new TestPlugin());
}
}
/* plugin class should be placed under ./application/plugins/ */
class TestPlugin extends Yaf_Plugin_Abstract {
public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
/* 锟斤拷路锟斤拷之前执锟斤拷,锟斤拷锟斤拷锟斤拷锟斤拷铮拷锟斤拷锟斤拷锟斤拷url锟斤拷写锟饺癸拷锟斤拷 */
var_dump("routerStartup");
}
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
/* 路锟斤拷锟斤拷珊锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤,锟斤拷锟斤拷锟斤拷锟斤拷锟铰斤拷锟斤拷裙锟斤拷锟�*/
var_dump("routerShutdown");
}
public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump("dispatchLoopStartup");
}
public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump("preDispatch");
}
public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump("postDispatch");
}
public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
/* final hoook
in this hook user can do loging or implement layout */
var_dump("dispatchLoopShutdown");
}
}
Class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
return FALSE; //prevent rendering
}
}
$config = array(
"application" => array(
"directory" => dirname(__FILE__) . "/application/",
),
);
$app = new Yaf_Application($config);
$app->bootstrap()->run();
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
string(13) "routerStartup" string(14) "routerShutdown" string(19) "dispatchLoopStartup" string(11) "preDispatch" string(12) "postDispatch" string(20) "dispatchLoopShutdown"
$request
, Yaf_Response_Abstract $response
) : void$request
, Yaf_Response_Abstract $response
) : void