Download the PHP package garrettw/noair without Composer
On this page you can find all versions of the php package garrettw/noair. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download garrettw/noair
More information about garrettw/noair
Files in garrettw/noair
Package noair
Short Description PHP event library following the Mediator behavioral pattern implemented like an Observer
License LGPL-2.1
Homepage https://github.com/garrettw/noair
Informations about the package noair
Noair
Noair (pronounced "no-air") is a PHP library that provides a central event hub that other things can hook into to handle events that are published into that hub. It implements the Mediator behavioral pattern in an Observer style.
"Why is it called that?"
We'll get to that in a minute.
"Why should I use Noair instead of all the other event libraries out there?"
Because Noair:
- Uses standard Observer-pattern terminology (publish/subscribe)
- Can optionally hang onto published events for which there is no subscriber until such time as a handler subscribes to it
- Supports timer events in addition to normal published events
- Allows handlers to subscribe to any and all events if they want
- Encapsulates event information in an object that gets passed to handlers
- Event objects can hold custom data set by the publisher for handlers to use
- Event objects allow handlers to access the objects that published them
- Event objects allow handlers to access previous handler output (for daisy-chaining)
- Event objects can prevent further daisy-chaining by calling setCancelled()
- Handlers can be simple anonymous functions or contained in observer objects; anything callable
- Observer objects can define handlers explicitly or use on() method naming, where is the capitalized event name
"I really need to know the meaning of the name."
Fine, fine. My project was forked from one called "Podiya", which is Ukrainian for "event". I found out what the word "Podiya" looked like in its original script, and I thought it looked like the letters n-o-A-i-R. See for yourself.
Core Principles
- Observers are objects with methods that are called by fired events.
- Those methods are called handlers, or once they are registered, subscribers.
- It is recommended (but optional) that observer objects be used to contain handlers.
Basic usage
The idea is that you have multiple event handlers watching a single event hub, waiting for events they can handle.
-
First, you'll create child classes of Noair's abstract Observer class that contain handlers:
-
Now, in the main code you're executing, you'll need to create a hub for your events: a Mediator object which serves as a go-between for your handlers and your code that fires/publishes the events.
-
Then, you can create objects of your own Observer classes and subscribe them to the hub.
- You will then use that Mediator object in your code to publish events that the Observer classes may handle.
Advanced usage
The only "advanced" thing you can do is set up handlers with custom method names,
custom priorities, or forceability (this means that the handler will be run even if
another handler higher up the chain tries to cancel the rest of the chain).
You do this by defining (actually, overriding) the subscribe()
method as follows:
That might return: do stuff 5623 times