work in progress
Warning
This project is not finished yet, work in progress.
You can install the package via composer:
composer require ghostwriter/router
// work in progress
$middlewares = [
ErrorHandlerMiddlewareInterface::class => ErrorHandlerMiddleware::class,
];
$route = new Route(['GET','HEAD'], '/', IndexRequestHandler::class, [GuestMiddleware::class], 'home');
$router = new Router($middlewares); // MiddlewareInterface
$router->withRoute($route);
$request = new ServerRequest();
$matched = $router->match($request); // CurrentRoute/RouteInterface
$router->addRoute('GET', '/', HomeHandler::class, [GuestMiddleware::class]);
$router->get('/about', AboutHandler::class, [GuestMiddleware::class]);
$router->get('/auth/github', GitHubLoginHandler::class, [GuestMiddleware::class], 'auth.login.github');
// create, read, edit, update, store, delete, view, show
$router->middleware([GuestMiddleware::class], function($router){
$router->get('/auth/login', LoginCreateHandler::class, 'auth.login.create');
$router->post('/auth/login', LoginStoreHandler::class, 'auth.login.store');
$router->get('/auth/register', RegisterCreateHandler::class, 'auth.register.create');
$router->post('/auth/register', RegisterStoreHandler::class, 'auth.register.store');
$router->get('/posts', PostIndexHandler::class, 'members.index');
$router->get('/posts/{post:id}', PostShowHandler::class, 'members.show');
});
$router->middleware([AuthMiddleware::class], function($router){
$router->get('/users', MembersIndexHandler::class, 'members.index');
$router->get('/users/{member:id}', MemberShowHandler::class, 'members.show');
$router->get('/posts/create', PostCreateHandler::class, 'members.create');
$router->post('/posts', PostStoreHandler::class, 'members.store');
$router->get('/posts/{post:id}/edit', PostEditHandler::class, 'members.edit');
$router->put('/posts/{post:id}', PostUpdateHandler::class, 'members.update');
$router->delete('/posts/{post:id}', PostDeleteHandler::class, 'members.delete');
});
Please see CHANGELOG.md for more information on what has changed recently.
If you discover any security-related issues, please use Security Advisories
instead of using the issue tracker.
The BSD-3-Clause. Please see License File for more information.