Swift has come a leap forward from it's version 2 days where learning to use the plugin system was a confusing business unless you knew Swift's core inside-out. In Version 3, things are clearer and simpler. The entire basis of the plugin system is centered around the concept of event-driven programming. Observers (Event Listeners) are plugged into Swift's core class. Swift then dispatches Events (as objects) to these event listeners.
If you're familiar with the observer pattern, you should be able to pick this up fairly easily. Otherwise, you probably want to have a read of this page first:
http://devzone.zend.com/node/view/id/5
There are subtle differences with how the system has been implemented in PHP5 and PHP4. Mostly these differences are the use of type checking in PHP5…. PHP4 is simply duck-typed.
There are a small number of events defined inside Swift. Each event has a listener specific to the event:
| Event | Listener | Listener Method |
|---|---|---|
| ConnectEvent | ConnectListener | connectPerformed( ConnectEvent $e ) |
| DisconnectEvent | DisconnectListener | disconnectPerformed( DisconnectEvent $e ) |
| BeforeSendEvent | BeforeSendListener | beforeSendPerformed( SendEvent $e) |
| SendEvent | SendListener | sendPerformed( SendEvent $e ) |
| BeforeCommandEvent | BeforeCommandListener | beforeCommandSent( CommandEvent $e ) |
| CommandEvent | CommandListener | commandSent( CommandEvent $e ) |
| ResponseEvent | ResponseListener | responseReceived( ResponseEvent $e ) |
NOTE: I've shortened the names for brevity on this page. The class names are actually in the format Swift_Events_SendEvent and Swift_Events_SendListener.
Any single plugin implements a listener for at least one of those events. A plugin can implement more than one listener if it needs to.
Each of the listeners listed above implements an interface with just one uniquely named method, we'll cover the actual methods used later in this documentation. The methods receive the event object as an argument and this event object will always contain a getSwift() method which returns a reference to the instance of Swift it was fired from. This gives you the ability to run methods in Swift from inside your plugin. Additional methods such as getMessage() and getConnection() will be present in each of the events.
When an event is fired, the following sequence occurs:
Event generated –> Listeners located → Listeners informed of event → Listeners carry out actions → Swift continues processing.
The next few pages in this wiki will discuss how to use each of the events.