The Yaf_Plugin_Abstract class

(Yaf >=1.0.0)

Introduction

Plugins allow for easy extensibility and customization of the framework.

Plugins are classes. The actual class definition will vary based on the component -- you may need to implement this interface, but the fact remains that the plugin is itself a class.

A plugin could be loaded into Yaf by using Yaf_Dispatcher::registerPlugin(), after registering, All the methods which the plugin implemented according to this interface, will be called at the proper time.

Examples

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 $requestYaf_Response_Abstract $response) {
            
/* before router 
               in this hook,  user can do some url rewrite */
            
var_dump("routerStartup");
        }
        public function 
routerShutdown(Yaf_Request_Abstract $requestYaf_Response_Abstract $response) {
            
/* router complete 
               in this hook, user can do login check */
            
var_dump("routerShutdown");
        }
        public function 
dispatchLoopStartup(Yaf_Request_Abstract $requestYaf_Response_Abstract $response) {
            
var_dump("dispatchLoopStartup");
        }
        public function 
preDispatch(Yaf_Request_Abstract $requestYaf_Response_Abstract $response) {
            
var_dump("preDispatch");
        }
        public function 
postDispatch(Yaf_Request_Abstract $requestYaf_Response_Abstract $response) {
            
var_dump("postDispatch");
        }
        public function 
dispatchLoopShutdown(Yaf_Request_Abstract $requestYaf_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();
?>

The above example will output something similar to:

string(13) "routerStartup"
string(14) "routerShutdown"
string(19) "dispatchLoopStartup"
string(11) "preDispatch"
string(12) "postDispatch"
string(20) "dispatchLoopShutdown"

Class synopsis

class Yaf_Plugin_Abstract {
/* Methods */
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 routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void
}

Table of Contents

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Definition of stored procedures - an introduction

Stored procedures are predefined SQL code blocks that are stored in a database and can be called up as required. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial