Преглед на файлове

Middlewares with string on class/function

ahwelp преди 5 години
родител
ревизия
47a08f5d49
променени са 1 файла, в които са добавени 8 реда и са изтрити 1 реда
  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);
+                }
             }
         }