Created
April 29, 2019 15:02
-
-
Save kobus1998/5c0569f67d66cc7b5714a05bdba826e7 to your computer and use it in GitHub Desktop.
Routing design
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 | |
$router = new Router(); | |
$router->addService('twig', $twig); | |
$router->addService('logger', function ($msg) { | |
echo $msg; | |
}); | |
$router->addRoute('GET', '/users', [Controller::class, 'getUsers']); | |
$router->addRoute('GET', '/users/:userId', [ $middleware ], function ($req, $res, $services) { | |
return $services->respond('123'); | |
}); | |
try { | |
$router->execute(); | |
} catch (\StatusFourZeroFour $e) { | |
$router->response->redirect('/404'); | |
} catch (\StatusForbidden $e) { | |
$router->response()->redirect('/'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment