소스 검색

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);
+                }
             }
         }