Last active
December 3, 2021 13:18
-
-
Save vakata/f91be1cd3cea764837bae8c5dc2b489b to your computer and use it in GitHub Desktop.
middleware callable dispatchers
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 for a stack of callables | |
| class Dispatcher | |
| { | |
| protected array $stack; | |
| public function __construct(array &$stack) | |
| { | |
| $this->stack = $stack; | |
| } | |
| public function __invoke(RequestInterface $req) | |
| { | |
| $handler = array_shift($this->stack); | |
| return call_user_func($handler, $req, new self($this->stack)); | |
| } | |
| } | |
| // single line function for a stack of callables | |
| $run = function ($req) use (&$stack, &$run) { return call_user_func(array_shift($stack), $req, $run); }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment