yii-ws-event-dispatcher EventDispatcher component a simple and effective make your projects truly extensible.

yii-ws-event-dispatcher

  1. Installation
  2. Usage examples

https://github.com/worksolutions/yii-ws-event-dispatcher

EventDispatcher component a simple and effective make your projects truly extensible.

Installation

Add a dependency to your project's composer.json:

{
    "require": {
        "worksolutions/yii-ws-event-dispatcher": "dev-master"
    }
}

Usage examples

Event call
$dispatcher = Yii::app()->eventDispatcher;

/** @var SomeEvent $event */
$event = $dispatcher->createEvent(SomeEvent::className(), $eventTestParams);
$dispatcher->fire($event);
Config EventDispatcher component
'components' => array(
    'eventDispatcher' => array(
        'class' => \WS\EventDispatcher\EventDispatcher::className(),
        'events' => array(
            SomeEvent::className() => array(
                array(
                     'class' => SomeHandler::className(),
                     'params' => array(),
                ),
                //...
            ),
            //...
        ),
    ),
    //...
)
Create handler class
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
use WS\EventDispatcher\Event;

class SomeEvent extends Event {
    public function attributeNames() {
        return array(
            'fieldName',
            //...
        );
    }

    public function rules() {
        return array(
            //validation rules
        );
    }
}
0 0
1 follower
89 downloads
Yii Version: 1.1
License: MIT
Category: Others
Developed by: worksolutions
Created on: Jun 3, 2014
Last updated: 6 years ago

Downloads

show all

Related Extensions