Here is a short class that will let you add events to a PHP project.
The class EventManager defines a singleton, which you access with the EventManager::getInstance() expression.
Here is the logic:
- bind a handler to an event: EventManager::getInstance()->bind( ‘event’, ‘handler’ )
An event can be a string or a PHP regular expression. A handler must be a PHP callable expression. - trigger an event: EventManager::getInstance()->trigger( ‘event’ )
A triggered event should be a string. That string is going to be matched against all the bound events. Whenever a match is found, all the handlers bound to the matching events will be called. All the arguments passed to trigger will be passed along to the handlers. If a handler returns a false value, all other handlers won’t be called.
{[ .EventManager | 1.hilite( =php= ) ]}