Skip to content

Latest commit

 

History

History
121 lines (84 loc) · 3.27 KB

README.md

File metadata and controls

121 lines (84 loc) · 3.27 KB

Koine Event Manager

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