Skip to content

Instantly share code, notes, and snippets.

@kieraneglin
Last active February 20, 2018 20:18
Show Gist options
  • Save kieraneglin/d9d7f4d69efaa5d0ffa79ed207f39cb1 to your computer and use it in GitHub Desktop.
Save kieraneglin/d9d7f4d69efaa5d0ffa79ed207f39cb1 to your computer and use it in GitHub Desktop.
<?php
include 'router.php';
foreach (glob('controllers'.DIRECTORY_SEPARATOR.'*_controller.php') as $filename) {
// Include all php files that end with `_controller.php` in the `controllers` directory
// Note that this does not recursively include files
include $filename;
}
$router = new Router();
// Traditional routes
$router->route('POST', '/posts', 'posts#create');
$router->route('GET', '/posts', 'posts#index');
$router->route('GET', '/posts/{:id}', 'posts#show');
$router->route('PATCH', '/posts/{:id}', 'posts#update');
$router->route('GET', '/me', 'users#show');
// Shorthand (Available for GET, POST, PATCH, PUTS, and DELETE)
$router->post('/posts', 'posts#create');
$router->get('/posts', 'posts#index');
$router->patch('/posts/{:id}', 'posts#update');
// Namespaced controllers
$router->route('GET', '/admin/settings', 'admin/settings#index');
// Catch-all route
$router->route('GET', '{:all}', 'pages#not_found');
$router->execute($_SERVER);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment