Created
March 14, 2018 16:55
-
-
Save Allenph1/28ac6264723058c87400c3fe04b3baf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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