Last active
November 30, 2016 15:15
-
-
Save boschDev/711942b575836ab02cdd7321f0a7341a to your computer and use it in GitHub Desktop.
microRouter
This file contains 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 'Route.php'; | |
$route = new Route; | |
$route->on('/', function(){ | |
echo 'home'; | |
}); | |
$route->on('/blog', function(){ | |
echo 'blog'; | |
}); | |
$route->run(); |
This file contains 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 | |
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