Development Wiki

Add Listeners

From phpBB Development Wiki

Revision as of 00:09, 15 June 2012 by Michaelc (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

NOTE: This article is a WIP by Unknown Bliss

What are listeners?

Listeners are a way of injecting code and manipulating variables in the code where events exist without editing the code. Numerous listeners form part of a subscriber. The listener is a method within your subscriber class in your extension, which is then identified as to which event it corresponds to by an identifying method. This sounds daunting but it a lot simpler in practice. They are part of the listeners system added in 3.1

What are subscribers?

A subscriber is a class which includes a set of listeners as methods, each of which can listen for an even to be triggered. They are 'linked' with the event by an identification method. You can have as many listeners inside a subscriber as you wish. You should only need 1 subscriber per extension however if you have a large number you may choose to split it up into several files.

Creating a subscriber

Explain the file name, directory to put it in, identifier method, which class to extend etc.

Creating a listener

Explain how it injects and how to manipulate variables.

Putting it together

Example of a subscriber file including 2 listeners