Implementing middlewares 0.1
This commit is contained in:
+19
-2
@@ -76,6 +76,10 @@ class Route{
|
||||
*/
|
||||
public $_ignore = false;
|
||||
|
||||
/*
|
||||
* Middlewares to remove from the list
|
||||
*/
|
||||
public $_middlewares_to_ignore = Array();
|
||||
/*
|
||||
* From Klein
|
||||
* HTTP status List
|
||||
@@ -135,12 +139,16 @@ class Route{
|
||||
|
||||
//=======================================================
|
||||
function execute(){
|
||||
foreach ($this->_before as $before){
|
||||
call_user_func($before);
|
||||
foreach ($this->_before as $key => $before){
|
||||
if(!in_array($key, $this->_middlewares_to_ignore) ){
|
||||
call_user_func($before);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->_callback as $callback){
|
||||
call_user_func_array($callback, $this->_params);
|
||||
}
|
||||
|
||||
foreach ($this->_after as $after){
|
||||
call_user_func($after);
|
||||
}
|
||||
@@ -199,6 +207,15 @@ class Route{
|
||||
$this->_ignore = false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
function middleware_ignore($name = ''){
|
||||
$this->_middlewares_to_ignore[$name];
|
||||
}
|
||||
|
||||
function middleware_add($name = '', $function){
|
||||
$this->_before[$name] = $function;
|
||||
}
|
||||
|
||||
function set_weight($weigth = 0){
|
||||
$this->_weight = $weigth;
|
||||
return $this;
|
||||
|
||||
Reference in New Issue
Block a user