https://github.com/worksolutions/yii-event-dispatcher
[deprecated]
https://github.com/worksolutions/yii-event-dispatcher
Last synced: 4 months ago
JSON representation
[deprecated]
- Host: GitHub
- URL: https://github.com/worksolutions/yii-event-dispatcher
- Owner: worksolutions
- Created: 2014-05-30T06:38:24.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-05T08:10:07.000Z (about 12 years ago)
- Last Synced: 2024-03-27T07:15:29.555Z (about 2 years ago)
- Language: PHP
- Homepage:
- Size: 258 KB
- Stars: 3
- Watchers: 6
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
yii-ws-event-dispatcher
=======================
[](https://travis-ci.org/worksolutions/yii-ws-event-dispatcher)
[](https://coveralls.io/r/worksolutions/yii-ws-event-dispatcher?branch=master)
EventDispatcher component a simple and effective make your projects truly extensible.
Installation
------------
Add a dependency to your project's composer.json:
```json
{
"require": {
"worksolutions/yii-ws-event-dispatcher": "dev-master"
}
}
```
Usage examples
--------------
#### Event call
```php
$dispatcher = Yii::app()->eventDispatcher;
/** @var SomeEvent $event */
$event = $dispatcher->createEvent(SomeEvent::className(), $eventTestParams);
$dispatcher->fire($event);
```
#### Config EventDispatcher component
```php
'components' => array(
'eventDispatcher' => array(
'class' => \WS\EventDispatcher\EventDispatcher::className(),
'events' => array(
SomeEvent::className() => array(
array(
'class' => SomeHandler::className(),
'params' => array(),
),
//...
),
//...
),
),
//...
)
```
#### Create handler class
```php
use WS\EventDispatcher\Handler;
class SomeHandler extends Handler {
protected function identity() {
// check the availability of execution
return true;
}
protected function process() {
// you handler code
}
}
```
#### Create event class
```php
use WS\EventDispatcher\Event;
class SomeEvent extends Event {
public function attributeNames() {
return array(
'fieldName',
//...
);
}
public function rules() {
return array(
//validation rules
);
}
}
```