mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
* Add phpstorm meta hints * composer fix-style * Use php-templates from vs-code * Fix view instance * composer fix-style * Add translations * composer fix-style * map to string * composer fix-style * Fix test --------- Co-authored-by: laravel-ide-helper <[email protected]>
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?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,
|
|
];
|
|
})
|
|
;
|