Hubert

Events

Hubert uses zend-eventmanager as Event Manager.

Installation

At first you have to extend the configuration of composer:

{
    "require": {
        "falkm/hubert-event": "1.*"
    }
}

Configuration

Afterwards you have to extend the configuration of Hubert or create a new config/event.global.php file. Just define the factory here:

<?php
return array(
    "factories" => array(
        "eventManager" => array(hubert\extension\event\factory::class, 'get')
    ),
);

Usage

$a =  hubert()->eventManager->trigger('do', null, ["test" => 2]);
print_r($a->last());

In this example the event "do" is executed. The is no scope given to the event but there is a variable "test". To make something happen you first have to pass an action to the event using attach($event_name, $event_target):

hubert()->eventManager->attach('do', function ($e) {
    $event = $e->getName();
    $params = $e->getParams();
    printf(
        'Handled event "%s", with parameters %s',
        $event,
        json_encode($params)
    );
    return "eventresult";
});

In this example the event outputs the parameters passed to it and returns a string. More detailed information on how to use Events you will finde at docs.zendframework.com/zend-eventmanager/.