@@ -69,37 +69,57 @@ public static function middleware(array $middleware, \Closure $closure): void {
69
69
}
70
70
71
71
public static function get (string $ url , \Closure |array $ controller_function , array $ filters = []): void {
72
- self ::executeMethod ('get ' , $ url , $ controller_function , $ filters );
72
+ if (count ($ filters ) > 0 ) {
73
+ self ::$ router ->get (
74
+ $ url ,
75
+ $ controller_function ,
76
+ isset ($ filters [1 ]) ? ['before ' => $ filters [0 ], 'after ' => $ filters [1 ]] : ['before ' => $ filters [0 ]]
77
+ );
78
+ } else {
79
+ self ::$ router ->get ($ url , $ controller_function );
80
+ }
73
81
}
74
82
75
83
public static function post (string $ url , \Closure |array $ controller_function , array $ filters = []): void {
76
- self ::executeMethod ('post ' , $ url , $ controller_function , $ filters );
84
+ if (count ($ filters ) > 0 ) {
85
+ self ::$ router ->post (
86
+ $ url ,
87
+ $ controller_function ,
88
+ isset ($ filters [1 ]) ? ['before ' => $ filters [0 ], 'after ' => $ filters [1 ]] : ['before ' => $ filters [0 ]]
89
+ );
90
+ } else {
91
+ self ::$ router ->post ($ url , $ controller_function );
92
+ }
77
93
}
78
94
79
95
public static function put (string $ url , \Closure |array $ controller_function , array $ filters = []): void {
80
- self ::executeMethod ('put ' , $ url , $ controller_function , $ filters );
96
+ if (count ($ filters ) > 0 ) {
97
+ self ::$ router ->put (
98
+ $ url ,
99
+ $ controller_function ,
100
+ isset ($ filters [1 ]) ? ['before ' => $ filters [0 ], 'after ' => $ filters [1 ]] : ['before ' => $ filters [0 ]]
101
+ );
102
+ } else {
103
+ self ::$ router ->put ($ url , $ controller_function );
104
+ }
81
105
}
82
106
83
107
public static function delete (string $ url , \Closure |array $ controller_function , array $ filters = []): void {
84
- self ::executeMethod ('delete ' , $ url , $ controller_function , $ filters );
85
- }
86
-
87
- public static function any (string $ url , \Closure |array $ controller_function , array $ filters = []): void {
88
- self ::executeMethod ('any ' , $ url , $ controller_function , $ filters );
89
- }
90
-
91
- private static function executeMethod (string $ methodType , string $ url , \Closure |array $ controller_function , array $ filters = []): void {
92
108
if (count ($ filters ) > 0 ) {
93
- self ::$ router ->$ methodType (
109
+ self ::$ router ->delete (
94
110
$ url ,
95
111
$ controller_function ,
96
112
isset ($ filters [1 ]) ? ['before ' => $ filters [0 ], 'after ' => $ filters [1 ]] : ['before ' => $ filters [0 ]]
97
113
);
98
114
} else {
99
- self ::$ router ->$ methodType ($ url , $ controller_function );
115
+ self ::$ router ->delete ($ url , $ controller_function );
100
116
}
101
117
}
102
118
119
+ public static function any (string $ url , \Closure |array $ controller_function , array $ filters = []): void {
120
+ self ::executeMethod ('any ' , $ url , $ controller_function , $ filters );
121
+ }
122
+
103
123
private static function processInput (int $ index ): string {
104
124
return implode ('/ ' , array_slice (explode ('/ ' , $ _SERVER ['REQUEST_URI ' ]), $ index ));
105
125
}
0 commit comments