Skip to content

Commit 1f3f27d

Browse files
Merge pull request #381 from N1ebieski/Fix-Middleware-handle-does-not-exist-on-invokable-middleware-files-#39
Fix Middleware "handle" does not exist on invokable middleware files
2 parents 0f94df4 + 2809b21 commit 1f3f27d

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 vsCodeGetReflectionMethod(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 = vsCodeGetReflectionMethod($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 = vsCodeGetReflectionMethod($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 vsCodeGetReflectionMethod(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 = vsCodeGetReflectionMethod($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 = vsCodeGetReflectionMethod($reflected);
4249
4350
$result = array_merge($result, [
4451
"class" => $middleware,

0 commit comments

Comments
 (0)