Removed nasty Config class

This commit is contained in:
steampixel 2018-03-12 16:58:57 +01:00
parent 0d9829796f
commit ee939f5c21
3 changed files with 14 additions and 32 deletions

View File

@ -1,17 +0,0 @@
<?PHP
class Config{
private static $registry = Array();
public static function set($key,$value){
self::$registry[$key] = $value;
}
public static function get($key){
if(array_key_exists($key,self::$registry)){
return self::$registry[$key];
}
return false;
}
}

View File

@ -2,12 +2,15 @@
class Route{
public static $routes = Array();
public static $routes404 = Array();
public static $path;
private static $routes = Array();
private static $routes404 = Array();
private static $path;
private static $basepath = '/';
public static function init(){
public static function init($basepath = '/'){
self::$basepath = $basepath;
$parsed_url = parse_url($_SERVER['REQUEST_URI']);//Parse Uri
if(isset($parsed_url['path'])){
@ -40,8 +43,8 @@ class Route{
foreach(self::$routes as $route){
// Add basepath to matching string
if(Config::get('basepath')&&Config::get('basepath')!=''&&Config::get('basepath')!='/'){
$route['expression'] = '('.Config::get('basepath').')'.$route['expression'];
if(self::$basepath!=''&&self::$basepath!='/'){
$route['expression'] = '('.self::$basepath.')'.$route['expression'];
}
// Add 'find string start' automatically
@ -57,7 +60,7 @@ class Route{
array_shift($matches);// Always remove first element. This contains the whole string
if(Config::get('basepath')&&Config::get('basepath')!=''&&Config::get('basepath')!='/'){
if(self::$basepath!=''&&self::$basepath!='/'){
array_shift($matches);// Remove Basepath

View File

@ -1,18 +1,14 @@
<?PHP
// Include needed files
include('Config.php');
include('Route.php');
// Configure basepath
// Init routing and configure basepath
// If your script lives in the web root folder use a / , leave it empty or do not define this config
Config::set('basepath','/');
Route::init('/');
// If your script lives in a subfolder you can use the following example
// Config::set('basepath','/api/v1');
// Init routing
Route::init();
// Route::init('/api/v1');
// Base route (startpage)
Route::add('/',function(){