Skip to content

Instantly share code, notes, and snippets.

@boschDev
Last active November 30, 2016 15:15
Show Gist options
  • Save boschDev/711942b575836ab02cdd7321f0a7341a to your computer and use it in GitHub Desktop.
Save boschDev/711942b575836ab02cdd7321f0a7341a to your computer and use it in GitHub Desktop.
microRouter
<?php
require 'Route.php';
$route = new Route;
$route->on('/', function(){
echo 'home';
});
$route->on('/blog', function(){
echo 'blog';
});
$route->run();
<?php
Class Route{
$routes = array();
function on($url,callable $call){
$this->routes[$url]=$call;
}
function notFound(callable $call){
$this->routes['404']=$call;
}
function run(){
$this->routes[isset($this->routes[$_SERVER['PATH_INFO']])?$_SERVER['PATH_INFO']:'404']();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment