From 730130e369c7526de67b1ec9283ab2dfab4eba8e Mon Sep 17 00:00:00 2001 From: SteamPixel Date: Thu, 10 Sep 2015 13:37:52 +0200 Subject: [PATCH] initial commit --- .htaccess | 10 +++++++ Config.php | 17 +++++++++++ Route.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.php | 39 ++++++++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 .htaccess create mode 100644 Config.php create mode 100644 Route.php create mode 100644 index.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..9681cf0 --- /dev/null +++ b/.htaccess @@ -0,0 +1,10 @@ +DirectoryIndex index.php + +RewriteEngine on + +RewriteBase / + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d + +RewriteRule ^(.*)$ index.php [QSA] \ No newline at end of file diff --git a/Config.php b/Config.php new file mode 100644 index 0000000..060558e --- /dev/null +++ b/Config.php @@ -0,0 +1,17 @@ +$expression, + 'function'=>$function + )); + + } + + public static function add404($function){ + + array_push(self::$routes404,$function); + + } + + public static function run(){ + + $route_found = false; + + foreach(self::$routes as $route){ + + if(Config::get('basepath')){ + + $route['expression'] = '('.Config::get('basepath').')/'.$route['expression']; + + } + + //Add 'find string start' automatically + $route['expression'] = '^'.$route['expression']; + + //Add 'find string end' automatically + $route['expression'] = $route['expression'].'$'; + + //check match + if(preg_match('#'.$route['expression'].'#',self::$path,$matches)){ + + //echo $expression; + + array_shift($matches);//Always remove first element. This contains the whole string + + if(Config::get('basepath')){ + + array_shift($matches);//Remove Basepath + + } + + call_user_func_array($route['function'], $matches); + + $route_found = true; + + } + + } + + if(!$route_found){ + + foreach(self::$routes404 as $route404){ + + call_user_func_array($route404, Array(self::$path)); + + } + + } + + } + +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..a05a55e --- /dev/null +++ b/index.php @@ -0,0 +1,39 @@ +