Simple Event Manager Code information:
Package information:
<?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
}
}
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.