Middleware and model binding in Mezon Router

$router = new Router();
$router->addRoute('/user/[i:id]', function(string $route, array $parameters){
$userModel = new UserModel();
$userObject = $userModel->getUserById($parameters[$id]);
// use $userObject for any purpose you need
});
$router = new Router();
$router->addRoute('/user/[i:id]', function(UserObject $userObject){
// here we get $userObject directly
// use use it in any way we need
});
$router->registerMiddleware('/user/[i:id]', function(string $route, array $parameters){
$userModel = new UserModel();
$userObject = $userModel->getUserById($parameters[$id]);
return $userObject;
});

Learn more

More information can be found here:

It will be great if you will contribute something to this project. Documentation, sharing the project in your social media, bug fixing, refactoring, or even submitting issue with question or feature request. Thanks anyway )

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store