koine / event-manager
Simple Event Manager
1.0
2016-02-18 13:23 UTC
Requires
- php: >=5.4
Requires (Dev)
- koine/db-test-case: *
- phpunit/phpunit: *
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-11-23 19:16:34 UTC
README
Simple Event Manager Code information:
Package information:
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
- Learn composer. You should not be looking for an alternative install. It is worth the time. Trust me ;-)
- Follow this set of instructions
Issues/Features proposals
Here is the issue tracker.