Prechádzať zdrojové kódy

Middlewares with string on class/function

ahwelp 5 rokov pred
rodič
commit
47a08f5d49
1 zmenil súbory, kde vykonal 8 pridanie a 1 odobranie
  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);
+                }
             }
         }