Yet Another Framework Yaf_Plugin_Abstract 클래스
(Yaf >=1.0.0)
소개
플러그인을 사용하면 프레임워크를 쉽게 확장하고 사용자 지정할 수 있습니다.
플러그인은 클래스입니다. 실제 클래스 정의는 구성 요소에 따라 다릅니다. 이 인터페이스를 구현해야 할 수도 있지만 플러그인 자체가 클래스라는 사실은 그대로 유지됩니다.
플러그인은 등록 후 Yaf_Dispatcher::registerPlugin()을 사용하여 Yaf에 로드할 수 있습니다. 이 인터페이스에 따라 플러그인이 구현한 모든 메소드는 적절한 시간에 호출됩니다.
Examples
예제 #1 플러그인 예시
<?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) {
/* before router
in this hook, user can do some url rewrite */
var_dump("routerStartup");
}
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
/* router complete
in this hook, user can do login check */
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 hook
in this hook user can do logging 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"
클래스 개요
class Yaf_Plugin_Abstract {
/* Methods */
public dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
public dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
public postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
public preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
public preResponse(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
public routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
public routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
}
목차
- Yaf_Plugin_Abstract::dispatchLoopShutdown — The dispatchLoopShutdown purpose
- Yaf_Plugin_Abstract::dispatchLoopStartup — Hook before dispatch loop
- Yaf_Plugin_Abstract::postDispatch — The postDispatch purpose
- Yaf_Plugin_Abstract::preDispatch — The preDispatch purpose
- Yaf_Plugin_Abstract::preResponse — The preResponse purpose
- Yaf_Plugin_Abstract::routerShutdown — The routerShutdown purpose
- Yaf_Plugin_Abstract::routerStartup — RouterStartup hook