Skip to content

Instantly share code, notes, and snippets.

@Allenph1
Created March 14, 2018 16:55
Show Gist options
  • Save Allenph1/28ac6264723058c87400c3fe04b3baf0 to your computer and use it in GitHub Desktop.
Save Allenph1/28ac6264723058c87400c3fe04b3baf0 to your computer and use it in GitHub Desktop.
class ThingThatEmitsAnEvent
{
private $dispatcher;
public function __construct(EventDispatcher $dispatcher) {
$this->dispatcher = $dispatcher;
}
public function doAThing() {
//Do Some Stuff
$this->dispatcher->(Event::NAME, new Event());
}
}
class ThingThatListens
{
private $dispatcher;
public function __construct(EventDispatcher $dispatcher) {
$this->dispatcher = $dispatcher;
$this->dispatcher->addListener("SomeEventName", function(Event $event) {
$this->doSomething($event->getId());
});
}
public doSomething($id) {
//Do Something With ID
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment