Implementing middlewares 0.1

This commit is contained in:
ahwelp
2018-08-20 21:22:15 -03:00
parent 8e5a67740e
commit 0e02aa0ca3
2 changed files with 47 additions and 11 deletions
+19 -2
View File
@@ -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;