koine/event-manager

Simple Event Manager

1.0 2016-02-18 13:23 UTC

This package is not auto-updated.

Last update: 2024-05-11 16:34:41 UTC


README

Simple Event Manager Code information:

Build Status Coverage Status Code Coverage Scrutinizer Code Climate Scrutinizer Code Quality StyleCI

Package information:

Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status

Usage

<?php

use Koine\EventManager\EventManager;

$eventManager = EventManager();

$eventManager->attach('MyApp\DomainEvents\UserRegistered', function ($event) {
    $user = $event->getUser();

    // send welcome email to user
});

The event

<?php

namespace MyApp\DomainEvents;

use MyApp\Entity\User;

class UserRegistered implements EventInterface
{
    private $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function getUser()
    {
        return $this->user;
    }
}

In the controller, service or anywhere else

<?php

namespace MyApp\Controller;

use MyApp\DomainEvents\UserRegistered;
use MyApp\Entity\User;

class UserRegistration extends BaseController
{
    public function createAction()
    {
        $params = $this->getRequest()->getParams();

        $user = new User($params);

        // logic to create ommited

        $this->getEventManager()->trigger(new UserRegistered($user));

        // redirect or wathever
    }
}

Installing

Installing Via Composer

Append the lib to your requirements key in your composer.json.

{
    // composer.json
    // [..]
    require: {
        // append this line to your requirements
        "koine/event-manager": "*"
    }
}

Alternative install

Issues/Features proposals

Here is the issue tracker.

Lincense

MIT

Authors