Simple Event Manager Code information:
Package information:
<?phpuseKoine\EventManager\EventManager;
$eventManager = EventManager();
$eventManager->attach('MyApp\DomainEvents\UserRegistered', function ($event) {
$user = $event->getUser();
// send welcome email to user
});The event
<?phpnamespaceMyApp\DomainEvents;
useMyApp\Entity\User;
class UserRegistered implements EventInterface
{
private$user;
publicfunction__construct(User$user)
{
$this->user = $user;
}
publicfunctiongetUser()
{
return$this->user;
}
}In the controller, service or anywhere else
<?phpnamespaceMyApp\Controller;
useMyApp\DomainEvents\UserRegistered;
useMyApp\Entity\User;
class UserRegistration extends BaseController
{
publicfunctioncreateAction()
{
$params = $this->getRequest()->getParams();
$user = newUser($params);
// logic to create ommited$this->getEventManager()->trigger(newUserRegistered($user));
// redirect or wathever
}
}Append the lib to your requirements key in your composer.json.
{// composer.json// [..]require: {// append this line to your requirements"koine/event-manager": "*"}}- Learn composer. You should not be looking for an alternative install. It is worth the time. Trust me ;-)
- Follow this set of instructions
Here is the issue tracker.





