Explorar el Código

Middlewares with string on class/function

ahwelp hace 5 años
padre
commit
47a08f5d49
Se han modificado 1 ficheros con 8 adiciones y 1 borrados
  1. 8 1
      src/Routes/Route.php

+ 8 - 1
src/Routes/Route.php

@@ -137,9 +137,16 @@ class Route {
 
     //=======================================================
     function execute() {
+        //Middlewares with function or class method
         foreach ($this->_before as $key => $before) {
             if (!in_array($key, $this->_middlewaresToIgnore) && !$this->_ignore) {
-                call_user_func($before);
+                if (is_string($before)) {
+                    $before = explode('@', $before);
+                    $class = new $before[0]();
+                    $class->{$before[1]}();
+                }else{
+                    call_user_func($before);
+                }
             }
         }