Last active
August 29, 2015 14:04
-
-
Save tomodutch/b7269d421c6ee80545ae to your computer and use it in GitHub Desktop.
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 | |
require_once('vendor/autoload.php'); | |
use TFarla\Routing\Router; | |
use TFarla\Routing\Route; | |
$router = new Router([ | |
new Route('show user', '^/users/(?P<id>\d+)/$', ['GET'], function($matches) { | |
return $matches['id']; | |
}), | |
new Route('list users', '^/users/$', ['GET'], function($matches) { | |
return 'users'; | |
}), | |
new Route('index', '^/$', ['GET'], function($matches) { | |
return 'index'; | |
}), | |
new Route('404', '', ['GET'], function($matches) { | |
return '404 - not found'; | |
}), | |
]); | |
$uri = $_SERVER['REQUEST_URI']; | |
$method = $_SERVER['REQUEST_METHOD']; | |
try { | |
list($route, $matches) = array_values($router->match($uri, $method)); | |
echo $route($matches); | |
} catch (\TFarla\Routing\RoutingException $routingException) { | |
die('No Route found.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment