Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phmlabs/annovent
Simple lightweight event dispatcher using annotations for registering listeners.
https://github.com/phmlabs/annovent
Last synced: 11 days ago
JSON representation
Simple lightweight event dispatcher using annotations for registering listeners.
- Host: GitHub
- URL: https://github.com/phmlabs/annovent
- Owner: phmLabs
- Created: 2011-03-04T08:16:38.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2019-05-05T17:11:40.000Z (over 5 years ago)
- Last Synced: 2024-10-02T21:37:40.891Z (about 2 months ago)
- Language: PHP
- Homepage: http://www.phmlabs.com/annovent
- Size: 52.7 KB
- Stars: 11
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
#Annovent
Annovent is a simple to use event dispatcher inspired by the symfony component event dispatching implementation. It tries to provide all the features symfony does with some useful extensions.
##Simple Usage
The Annovent dispatcher can be used in a simple and standard way as you are used from symfony:
```php
$dispatcher = new Dispatcher();
$dispatcher->connect('SomeComponent.Render', array($listener, 'Method1'));
$dispatcher->notify(new Event('SomeComponent.Render', array('foo' => 'bar'));
```##Namespace
An extra feature of this event dispatcher is the so called namespacing. It is possible to register a lister to a complete set events belonging to a special namespace.
```php
$dispatcher->connect('SomeComponent.*', array($listener, 'Method1'));
$dispatcher->connect('*', array($listener, 'Method2'));
```The first listener will be notified whenever a event is fired that starts with SomeComponent. The second one will always be notified.
##Annotation
Connection a listener to a special event is not limited to the connect method. It is also possible to register a listener using annotation (see doctrine common).
```php
class Listener
{
/**
* @Event("SomeComponent.Render")
*/
public function method1(Event $event)
{
}
}$dispatcher->connectListener( new Listener );
```Using the connectListener method it is possible to connect a bunch of callbacks at once.
##Named Parameters
If desired the event dispatcher can be used with named parameters.
```php
class Listener2
{
/**
* @Event("SomeComponent.Render")
*/
public function method1($argument1, $foo)
{
}
}
$dispatcher->notify(new Event('SomeComponent.Render', array('foo' => 'bar', 'argument1' => 'arg1' ));
```