mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
Use php-templates from vs-code
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
function vsCodeGetRouterReflection(\Illuminate\Routing\Route $route)
|
||||
{
|
||||
if ($route->getActionName() === 'Closure') {
|
||||
return new \ReflectionFunction($route->getAction()['uses']);
|
||||
}
|
||||
|
||||
if (!str_contains($route->getActionName(), '@')) {
|
||||
return new \ReflectionClass($route->getActionName());
|
||||
}
|
||||
|
||||
try {
|
||||
return new \ReflectionMethod($route->getControllerClass(), $route->getActionMethod());
|
||||
} catch (\Throwable $e) {
|
||||
$namespace = app(\Illuminate\Routing\UrlGenerator::class)->getRootControllerNamespace()
|
||||
?? (app()->getNamespace() . 'Http\Controllers');
|
||||
|
||||
return new \ReflectionMethod(
|
||||
$namespace . '\\' . ltrim($route->getControllerClass(), '\\'),
|
||||
$route->getActionMethod(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return collect(app('router')->getRoutes()->getRoutes())
|
||||
->map(function (\Illuminate\Routing\Route $route) {
|
||||
try {
|
||||
$reflection = vsCodeGetRouterReflection($route);
|
||||
} catch (\Throwable $e) {
|
||||
$reflection = null;
|
||||
}
|
||||
|
||||
return [
|
||||
'method' => collect($route->methods())->filter(function ($method) {
|
||||
return $method !== 'HEAD';
|
||||
})->implode('|'),
|
||||
'uri' => $route->uri(),
|
||||
'name' => $route->getName(),
|
||||
'action' => $route->getActionName(),
|
||||
'parameters' => $route->parameterNames(),
|
||||
'filename' => $reflection ? $reflection->getFileName() : null,
|
||||
'line' => $reflection ? $reflection->getStartLine() : null,
|
||||
];
|
||||
})
|
||||
;
|
||||
Reference in New Issue
Block a user