Skip to content

Instantly share code, notes, and snippets.

@flesch
Created December 3, 2010 03:49
Show Gist options
  • Save flesch/726556 to your computer and use it in GitHub Desktop.
Save flesch/726556 to your computer and use it in GitHub Desktop.
Simple PHP router.
<?php
/*******************************************************************************
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
*******************************************************************************/
/*
application.class.php
*/
class Application {
public static function route() {
$route = explode('/', str_replace('/route/', '', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
call_user_func_array(array(array_shift($route), array_shift($route)), $route);
}
}
/*
view.class.php
*/
class View {
public static function pdf($id) {
echo sprintf('view: %s.pdf', $id);
}
}
/*
download.class.php
*/
class Download {
public static function pdf($id) {
echo sprintf('download: %s.pdf', $id);
}
}
header('Content-Type: text/plain');
// http://api.fles.ch/route/view/pdf/4f8278c89ad16da05fec4fdfc61fe44798b92720
// http://api.fles.ch/route/download/pdf/4f8278c89ad16da05fec4fdfc61fe44798b92720
Application::route();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment