Cleaned up code
This commit is contained in:
parent
8699df0060
commit
140681593c
14
Route.php
14
Route.php
|
@ -15,7 +15,7 @@ class Route{
|
||||||
}else{
|
}else{
|
||||||
self::$path = '/';
|
self::$path = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function add($expression,$function){
|
public static function add($expression,$function){
|
||||||
|
@ -41,11 +41,11 @@ class Route{
|
||||||
|
|
||||||
if(Config::get('basepath')){
|
if(Config::get('basepath')){
|
||||||
|
|
||||||
//Add / if its not empty
|
//Add / if its not empty
|
||||||
if($route['expression']!=''){
|
if($route['expression']!=''){
|
||||||
$route['expression'] = '/'.$route['expression'];
|
$route['expression'] = '/'.$route['expression'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$route['expression'] = '('.Config::get('basepath').')'.$route['expression'];
|
$route['expression'] = '('.Config::get('basepath').')'.$route['expression'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class Route{
|
||||||
//Add 'find string end' automatically
|
//Add 'find string end' automatically
|
||||||
$route['expression'] = $route['expression'].'$';
|
$route['expression'] = $route['expression'].'$';
|
||||||
|
|
||||||
//echo $route['expression'].'<br/>';
|
//echo $route['expression'].'<br/>';
|
||||||
|
|
||||||
//check match
|
//check match
|
||||||
if(preg_match('#'.$route['expression'].'#',self::$path,$matches)){
|
if(preg_match('#'.$route['expression'].'#',self::$path,$matches)){
|
||||||
|
|
12
index.php
12
index.php
|
@ -5,7 +5,7 @@ include('Config.php');
|
||||||
include('Route.php');
|
include('Route.php');
|
||||||
|
|
||||||
//config
|
//config
|
||||||
Config::set('basepath','');
|
Config::set('basepath','/api/v1');
|
||||||
|
|
||||||
//init routing
|
//init routing
|
||||||
Route::init();
|
Route::init();
|
||||||
|
@ -52,6 +52,16 @@ Route::add('/(.*)/(.*)/(.*)/(.*)',function($var1,$var2,$var3,$var4){
|
||||||
echo 'You have entered: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'<br/>';
|
echo 'You have entered: '.$var1.' / '.$var2.' / '.$var3.' / '.$var4.'<br/>';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::add('/api/v1/deployment/(.*)',function($id){
|
||||||
|
//Do something
|
||||||
|
echo $id;
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::add('/deployment/(.*)',function($id){
|
||||||
|
//Do something
|
||||||
|
echo $id;
|
||||||
|
});
|
||||||
|
|
||||||
//Add a 404 Not found Route
|
//Add a 404 Not found Route
|
||||||
Route::add404(function($url){
|
Route::add404(function($url){
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user