mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Merge branch 'feat-meta-hints' of github.com:barryvdh/laravel-ide-helper into feat-meta-hints
This commit is contained in:
+32
-31
@@ -1,40 +1,41 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$local = collect(glob(config_path("/*.php")))
|
$local = collect(glob(config_path('/*.php')))
|
||||||
->merge(glob(config_path("**/*.php")))
|
->merge(glob(config_path('**/*.php')))
|
||||||
->map(fn ($path) => [
|
->map(fn ($path) => [
|
||||||
(string) \Illuminate\Support\Str::of($path)
|
(string) Illuminate\Support\Str::of($path)
|
||||||
->replace([config_path("/"), ".php"], "")
|
->replace([config_path('/'), '.php'], '')
|
||||||
->replace("/", "."),
|
->replace('/', '.'),
|
||||||
$path
|
$path,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$vendor = collect(glob(base_path("vendor/**/**/config/*.php")))->map(fn (
|
$vendor = collect(glob(base_path('vendor/**/**/config/*.php')))->map(fn (
|
||||||
$path
|
$path
|
||||||
) => [
|
) => [
|
||||||
(string) \Illuminate\Support\Str::of($path)
|
(string) Illuminate\Support\Str::of($path)
|
||||||
->afterLast("/config/")
|
->afterLast('/config/')
|
||||||
->replace(".php", "")
|
->replace('.php', '')
|
||||||
->replace("/", "."),
|
->replace('/', '.'),
|
||||||
$path
|
$path,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$configPaths = $local
|
$configPaths = $local
|
||||||
->merge($vendor)
|
->merge($vendor)
|
||||||
->groupBy(0)
|
->groupBy(0)
|
||||||
->map(fn ($items)=>$items->pluck(1));
|
->map(fn ($items) => $items->pluck(1));
|
||||||
|
|
||||||
$cachedContents = [];
|
$cachedContents = [];
|
||||||
$cachedParsed = [];
|
$cachedParsed = [];
|
||||||
|
|
||||||
function vsCodeGetConfigValue($value, $key, $configPaths) {
|
function vsCodeGetConfigValue($value, $key, $configPaths)
|
||||||
$parts = explode(".", $key);
|
{
|
||||||
|
$parts = explode('.', $key);
|
||||||
$toFind = $key;
|
$toFind = $key;
|
||||||
$found = null;
|
$found = null;
|
||||||
|
|
||||||
while (count($parts) > 0) {
|
while (count($parts) > 0) {
|
||||||
array_pop($parts);
|
array_pop($parts);
|
||||||
$toFind = implode(".", $parts);
|
$toFind = implode('.', $parts);
|
||||||
|
|
||||||
if ($configPaths->has($toFind)) {
|
if ($configPaths->has($toFind)) {
|
||||||
$found = $toFind;
|
$found = $toFind;
|
||||||
@@ -56,22 +57,22 @@ function vsCodeGetConfigValue($value, $key, $configPaths) {
|
|||||||
$cachedContents[$path] ??= file_get_contents($path);
|
$cachedContents[$path] ??= file_get_contents($path);
|
||||||
$cachedParsed[$path] ??= token_get_all($cachedContents[$path]);
|
$cachedParsed[$path] ??= token_get_all($cachedContents[$path]);
|
||||||
|
|
||||||
$keysToFind = \Illuminate\Support\Str::of($key)
|
$keysToFind = Illuminate\Support\Str::of($key)
|
||||||
->replaceFirst($found, "")
|
->replaceFirst($found, '')
|
||||||
->ltrim(".")
|
->ltrim('.')
|
||||||
->explode(".");
|
->explode('.');
|
||||||
|
|
||||||
if (is_numeric($keysToFind->last())) {
|
if (is_numeric($keysToFind->last())) {
|
||||||
$index = $keysToFind->pop();
|
$index = $keysToFind->pop();
|
||||||
|
|
||||||
if ($index !== "0") {
|
if ($index !== '0') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = collect(explode(".", $key));
|
$key = collect(explode('.', $key));
|
||||||
$key->pop();
|
$key->pop();
|
||||||
$key = $key->implode(".");
|
$key = $key->implode('.');
|
||||||
$value = "array(...)";
|
$value = 'array(...)';
|
||||||
}
|
}
|
||||||
|
|
||||||
$nextKey = $keysToFind->shift();
|
$nextKey = $keysToFind->shift();
|
||||||
@@ -80,11 +81,11 @@ function vsCodeGetConfigValue($value, $key, $configPaths) {
|
|||||||
$depth = 0;
|
$depth = 0;
|
||||||
|
|
||||||
foreach ($cachedParsed[$path] as $token) {
|
foreach ($cachedParsed[$path] as $token) {
|
||||||
if ($token === "[") {
|
if ($token === '[') {
|
||||||
$depth++;
|
$depth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($token === "]") {
|
if ($token === ']') {
|
||||||
$depth--;
|
$depth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,14 +118,14 @@ function vsCodeGetConfigValue($value, $key, $configPaths) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"name" => $key,
|
'name' => $key,
|
||||||
"value" => $value,
|
'value' => $value,
|
||||||
"file" => $file === null ? null : str_replace(base_path('/'), '', $file),
|
'file' => $file === null ? null : str_replace(base_path('/'), '', $file),
|
||||||
"line" => $line
|
'line' => $line,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return collect(\Illuminate\Support\Arr::dot(config()->all()))
|
return collect(Illuminate\Support\Arr::dot(config()->all()))
|
||||||
->map(fn ($value, $key) => vsCodeGetConfigValue($value, $key, $configPaths))
|
->map(fn ($value, $key) => vsCodeGetConfigValue($value, $key, $configPaths))
|
||||||
->filter()
|
->filter()
|
||||||
->values();
|
->values();
|
||||||
|
|||||||
+10
-10
@@ -1,22 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function vsCodeGetRouterReflection(\Illuminate\Routing\Route $route)
|
function vsCodeGetRouterReflection(Illuminate\Routing\Route $route)
|
||||||
{
|
{
|
||||||
if ($route->getActionName() === 'Closure') {
|
if ($route->getActionName() === 'Closure') {
|
||||||
return new \ReflectionFunction($route->getAction()['uses']);
|
return new ReflectionFunction($route->getAction()['uses']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!str_contains($route->getActionName(), '@')) {
|
if (!str_contains($route->getActionName(), '@')) {
|
||||||
return new \ReflectionClass($route->getActionName());
|
return new ReflectionClass($route->getActionName());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new \ReflectionMethod($route->getControllerClass(), $route->getActionMethod());
|
return new ReflectionMethod($route->getControllerClass(), $route->getActionMethod());
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$namespace = app(\Illuminate\Routing\UrlGenerator::class)->getRootControllerNamespace()
|
$namespace = app(Illuminate\Routing\UrlGenerator::class)->getRootControllerNamespace()
|
||||||
?? (app()->getNamespace() . 'Http\Controllers');
|
?? (app()->getNamespace() . 'Http\Controllers');
|
||||||
|
|
||||||
return new \ReflectionMethod(
|
return new ReflectionMethod(
|
||||||
$namespace . '\\' . ltrim($route->getControllerClass(), '\\'),
|
$namespace . '\\' . ltrim($route->getControllerClass(), '\\'),
|
||||||
$route->getActionMethod(),
|
$route->getActionMethod(),
|
||||||
);
|
);
|
||||||
@@ -24,10 +24,10 @@ function vsCodeGetRouterReflection(\Illuminate\Routing\Route $route)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return collect(app('router')->getRoutes()->getRoutes())
|
return collect(app('router')->getRoutes()->getRoutes())
|
||||||
->map(function (\Illuminate\Routing\Route $route) {
|
->map(function (Illuminate\Routing\Route $route) {
|
||||||
try {
|
try {
|
||||||
$reflection = vsCodeGetRouterReflection($route);
|
$reflection = vsCodeGetRouterReflection($route);
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$reflection = null;
|
$reflection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,4 +43,4 @@ return collect(app('router')->getRoutes()->getRoutes())
|
|||||||
'line' => $reflection ? $reflection->getStartLine() : null,
|
'line' => $reflection ? $reflection->getStartLine() : null,
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
|
|||||||
+15
-16
@@ -9,27 +9,26 @@ function vsCodeFindBladeFiles($path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (
|
foreach (
|
||||||
\Symfony\Component\Finder\Finder::create()
|
Symfony\Component\Finder\Finder::create()
|
||||||
->files()
|
->files()
|
||||||
->name("*.blade.php")
|
->name('*.blade.php')
|
||||||
->in($path)
|
->in($path) as $file
|
||||||
as $file
|
|
||||||
) {
|
) {
|
||||||
$paths[] = [
|
$paths[] = [
|
||||||
"path" => str_replace(base_path(DIRECTORY_SEPARATOR), '', $file->getRealPath()),
|
'path' => str_replace(base_path(DIRECTORY_SEPARATOR), '', $file->getRealPath()),
|
||||||
"isVendor" => str_contains($file->getRealPath(), base_path("vendor")),
|
'isVendor' => str_contains($file->getRealPath(), base_path('vendor')),
|
||||||
"key" => \Illuminate\Support\Str::of($file->getRealPath())
|
'key' => Illuminate\Support\Str::of($file->getRealPath())
|
||||||
->replace(realpath($path), "")
|
->replace(realpath($path), '')
|
||||||
->replace(".blade.php", "")
|
->replace('.blade.php', '')
|
||||||
->ltrim(DIRECTORY_SEPARATOR)
|
->ltrim(DIRECTORY_SEPARATOR)
|
||||||
->replace(DIRECTORY_SEPARATOR, ".")
|
->replace(DIRECTORY_SEPARATOR, '.'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $paths;
|
return $paths;
|
||||||
}
|
}
|
||||||
$paths = collect(
|
$paths = collect(
|
||||||
app("view")
|
app('view')
|
||||||
->getFinder()
|
->getFinder()
|
||||||
->getPaths()
|
->getPaths()
|
||||||
)->flatMap(function ($path) {
|
)->flatMap(function ($path) {
|
||||||
@@ -37,7 +36,7 @@ $paths = collect(
|
|||||||
});
|
});
|
||||||
|
|
||||||
$hints = collect(
|
$hints = collect(
|
||||||
app("view")
|
app('view')
|
||||||
->getFinder()
|
->getFinder()
|
||||||
->getHints()
|
->getHints()
|
||||||
)->flatMap(function ($paths, $key) {
|
)->flatMap(function ($paths, $key) {
|
||||||
@@ -45,7 +44,7 @@ $hints = collect(
|
|||||||
return collect(vsCodeFindBladeFiles($path))->map(function ($value) use (
|
return collect(vsCodeFindBladeFiles($path))->map(function ($value) use (
|
||||||
$key
|
$key
|
||||||
) {
|
) {
|
||||||
return array_merge($value, ["key" => "{$key}::{$value["key"]}"]);
|
return array_merge($value, ['key' => "{$key}::{$value['key']}"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -54,9 +53,9 @@ $hints = collect(
|
|||||||
->merge($hints)
|
->merge($hints)
|
||||||
->values()
|
->values()
|
||||||
->partition(function ($v) {
|
->partition(function ($v) {
|
||||||
return !$v["isVendor"];
|
return !$v['isVendor'];
|
||||||
});
|
});
|
||||||
|
|
||||||
return $local
|
return $local
|
||||||
->sortBy("key", SORT_NATURAL)
|
->sortBy('key', SORT_NATURAL)
|
||||||
->merge($vendor->sortBy("key", SORT_NATURAL));
|
->merge($vendor->sortBy('key', SORT_NATURAL));
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ class MetaCommand extends Command
|
|||||||
protected function loadTemplate($name)
|
protected function loadTemplate($name)
|
||||||
{
|
{
|
||||||
if (!isset($this->templates[$name])) {
|
if (!isset($this->templates[$name])) {
|
||||||
$file = __DIR__ . '/../../php-templates/' . basename($name) .'.php';
|
$file = __DIR__ . '/../../php-templates/' . basename($name) . '.php';
|
||||||
$this->templates[$name] = $this->files->requireOnce($file);
|
$this->templates[$name] = $this->files->requireOnce($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ use Illuminate\Console\Events\CommandFinished;
|
|||||||
use Illuminate\Contracts\Support\DeferrableProvider;
|
use Illuminate\Contracts\Support\DeferrableProvider;
|
||||||
use Illuminate\Database\Events\MigrationsEnded;
|
use Illuminate\Database\Events\MigrationsEnded;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\View\Engines\EngineResolver;
|
|
||||||
use Illuminate\View\Engines\PhpEngine;
|
|
||||||
use Illuminate\View\Factory;
|
|
||||||
use Illuminate\View\FileViewFinder;
|
|
||||||
|
|
||||||
class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProvider
|
class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProvider
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user