The Yaf_Plugin_Abstract class

(Yaf >=1.0.0)

Einführung

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.

Beispiele

Beispiel #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();
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

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

Klassenbeschreibung

class Yaf_Plugin_Abstract {
/* Methoden */
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
}

Inhaltsverzeichnis

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Seltsames Verhalten von execute() oder Fehler meinerseits

Hello You can check below steps - Check for errors after executing the statement. Bind parameters to placeholders in the SQL query. Confirm t ...

Geschrieben von nolanmaris am 20.05.2024 12:12:16
Forum: SQL / Datenbanken
Ein Problem mit der Lampe

Yes ..i was facing the same issue .

Geschrieben von nolanmaris am 20.05.2024 12:02:55
Forum: Off-Topic Diskussionen
Hello

Hello , I am new member here. I have around 8years of experience in developing User Interfaces for Mobile/Tablet/Desktop using HTML, CSS, JavaScri ...

Geschrieben von nolanmaris am 20.05.2024 12:01:22
Forum: User stellen sich vor
Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Warum soll ich float meiden? Siehe https://www.linkedin.com/pulse/css-float-vs-grid-flexbox-sachin-tiwari Falls es mit Englisch nicht so klappt: ...

Geschrieben von scatello am 18.05.2024 05:57:56
Forum: PHP Developer Forum