Skip to content

Commit a4d4b0c

Browse files
committed
Fix Middleware "handle" does not exist on invokable middleware files
Fixes N1ebieski#39
1 parent 0f94df4 commit a4d4b0c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

php-templates/middleware.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?php
22

3+
function getReflectionMethod(ReflectionClass $reflected): ReflectionMethod {
4+
return match (true) {
5+
$reflected->hasMethod('__invoke') => $reflected->getMethod('__invoke'),
6+
default => $reflected->getMethod('handle'),
7+
};
8+
}
9+
310
echo collect(app("Illuminate\Contracts\Http\Kernel")->getMiddlewareGroups())
411
->merge(app("Illuminate\Contracts\Http\Kernel")->getRouteMiddleware())
512
->map(function ($middleware, $key) {
@@ -22,7 +29,7 @@
2229
}
2330

2431
$reflected = new ReflectionClass($m);
25-
$reflectedMethod = $reflected->getMethod("handle");
32+
$reflectedMethod = getReflectionMethod($reflected);
2633

2734
return [
2835
"class" => $m,
@@ -38,7 +45,7 @@
3845
}
3946

4047
$reflected = new ReflectionClass($middleware);
41-
$reflectedMethod = $reflected->getMethod("handle");
48+
$reflectedMethod = getReflectionMethod($reflected);
4249

4350
$result = array_merge($result, [
4451
"class" => $middleware,

src/templates/middleware.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// This file was generated from php-templates/middleware.php, do not edit directly
22
export default `
3+
function getReflectionMethod(ReflectionClass $reflected): ReflectionMethod {
4+
return match (true) {
5+
$reflected->hasMethod('__invoke') => $reflected->getMethod('__invoke'),
6+
default => $reflected->getMethod('handle'),
7+
};
8+
}
9+
310
echo collect(app("Illuminate\\Contracts\\Http\\Kernel")->getMiddlewareGroups())
411
->merge(app("Illuminate\\Contracts\\Http\\Kernel")->getRouteMiddleware())
512
->map(function ($middleware, $key) {
@@ -22,7 +29,7 @@ echo collect(app("Illuminate\\Contracts\\Http\\Kernel")->getMiddlewareGroups())
2229
}
2330
2431
$reflected = new ReflectionClass($m);
25-
$reflectedMethod = $reflected->getMethod("handle");
32+
$reflectedMethod = getReflectionMethod($reflected);
2633
2734
return [
2835
"class" => $m,
@@ -38,7 +45,7 @@ echo collect(app("Illuminate\\Contracts\\Http\\Kernel")->getMiddlewareGroups())
3845
}
3946
4047
$reflected = new ReflectionClass($middleware);
41-
$reflectedMethod = $reflected->getMethod("handle");
48+
$reflectedMethod = getReflectionMethod($reflected);
4249
4350
$result = array_merge($result, [
4451
"class" => $middleware,

0 commit comments

Comments
 (0)