Yii Framework Forum: Yii-Ws-Event-Dispatcher - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii-Ws-Event-Dispatcher EventDispatcher component a simple and effective make your projects tr Rate Topic: -----

#1 User is offline   worksolutions 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 30-May 14

Posted 03 June 2014 - 03:22 PM

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

Config EventDispatcher component

'components' => array(
    'eventDispatcher' => array(
        'class' => \WS\EventDispatcher\EventDispatcher::className(),
        'events' => array(
            SomeEvent::className() => 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
        );
    }
}


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

/** @var SomeEvent $event */
$event = $dispatcher->createEvent(SomeEvent::className(), $eventTestParams);
$dispatcher->fire($event);


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users