Last active
January 12, 2018 07:50
-
-
Save SamMousa/1efbe706efc93a3797892cd6243bf982 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
class EventHandler.php { | |
private $handlerClass; | |
public function __construct(string $handlerClass) { | |
$this->handlerClass = $handlerClass | |
} | |
public function __invoke(... $args) { | |
$instance = new {$this->handlerClass}; | |
$instance->handle(... $args); | |
} | |
} | |
// Usage | |
$config = [ | |
'on afterLogin' => new EventHandler(AfterLoginHandler::class) | |
] |
And EventHandlerInterface? ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note this is pseudo code :)