mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
Add more metadata (#1646)
* Add more metadata * composer fix-style * Parse .env * composer fix-style * Check if .env exists --------- Co-authored-by: laravel-ide-helper <[email protected]>
This commit is contained in:
co-authored by
laravel-ide-helper
parent
cffcd07e98
commit
f8381565ad
+2
-1
@@ -38,7 +38,8 @@
|
|||||||
"orchestra/testbench": "^9.2",
|
"orchestra/testbench": "^9.2",
|
||||||
"phpunit/phpunit": "^10.5",
|
"phpunit/phpunit": "^10.5",
|
||||||
"spatie/phpunit-snapshot-assertions": "^4 || ^5",
|
"spatie/phpunit-snapshot-assertions": "^4 || ^5",
|
||||||
"vimeo/psalm": "^5.4"
|
"vimeo/psalm": "^5.4",
|
||||||
|
"vlucas/phpdotenv": "^5"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"illuminate/events": "Required for automatic helper generation (^6|^7|^8|^9|^10|^11)."
|
"illuminate/events": "Required for automatic helper generation (^6|^7|^8|^9|^10|^11)."
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return collect(Illuminate\Support\Facades\Gate::abilities())
|
||||||
|
->map(function ($policy, $key) {
|
||||||
|
$reflection = new ReflectionFunction($policy);
|
||||||
|
|
||||||
|
$policyClass = null;
|
||||||
|
|
||||||
|
if (get_class($reflection->getClosureThis()) === Illuminate\Auth\Access\Gate::class) {
|
||||||
|
$vars = $reflection->getClosureUsedVariables();
|
||||||
|
|
||||||
|
if (isset($vars['callback'])) {
|
||||||
|
[$policyClass, $method] = explode('@', $vars['callback']);
|
||||||
|
|
||||||
|
$reflection = new ReflectionMethod($policyClass, $method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'key' => $key,
|
||||||
|
'uri' => $reflection->getFileName(),
|
||||||
|
'policy_class' => $policyClass,
|
||||||
|
'lineNumber' => $reflection->getStartLine(),
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->merge(
|
||||||
|
collect(Illuminate\Support\Facades\Gate::policies())->flatMap(function ($policy, $model) {
|
||||||
|
$methods = (new ReflectionClass($policy))->getMethods();
|
||||||
|
|
||||||
|
return collect($methods)->map(function (ReflectionMethod $method) use ($policy) {
|
||||||
|
return [
|
||||||
|
'key' => $method->getName(),
|
||||||
|
'uri' => $method->getFileName(),
|
||||||
|
'policy_class' => $policy,
|
||||||
|
'lineNumber' => $method->getStartLine(),
|
||||||
|
];
|
||||||
|
})->filter(function ($ability) {
|
||||||
|
return !in_array($ability['key'], ['allow', 'deny']);
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
->values()
|
||||||
|
->groupBy('key');
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return collect(app("Illuminate\Contracts\Http\Kernel")->getMiddlewareGroups())
|
||||||
|
->merge(app("Illuminate\Contracts\Http\Kernel")->getRouteMiddleware())
|
||||||
|
->map(function ($middleware, $key) {
|
||||||
|
$result = [
|
||||||
|
'class' => null,
|
||||||
|
'uri' => null,
|
||||||
|
'startLine' => null,
|
||||||
|
'parameters' => null,
|
||||||
|
'groups' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (is_array($middleware)) {
|
||||||
|
$result['groups'] = collect($middleware)->map(function ($m) {
|
||||||
|
if (!class_exists($m)) {
|
||||||
|
return [
|
||||||
|
'class' => $m,
|
||||||
|
'uri' => null,
|
||||||
|
'startLine' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflected = new ReflectionClass($m);
|
||||||
|
$reflectedMethod = $reflected->getMethod('handle');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'class' => $m,
|
||||||
|
'uri' => $reflected->getFileName(),
|
||||||
|
'startLine' =>
|
||||||
|
$reflectedMethod->getFileName() === $reflected->getFileName()
|
||||||
|
? $reflectedMethod->getStartLine()
|
||||||
|
: null,
|
||||||
|
];
|
||||||
|
})->all();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflected = new ReflectionClass($middleware);
|
||||||
|
$reflectedMethod = $reflected->getMethod('handle');
|
||||||
|
|
||||||
|
$result = array_merge($result, [
|
||||||
|
'class' => $middleware,
|
||||||
|
'uri' => $reflected->getFileName(),
|
||||||
|
'startLine' => $reflectedMethod->getStartLine(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$parameters = collect($reflectedMethod->getParameters())
|
||||||
|
->filter(function ($rc) {
|
||||||
|
return $rc->getName() !== 'request' && $rc->getName() !== 'next';
|
||||||
|
})
|
||||||
|
->map(function ($rc) {
|
||||||
|
return $rc->getName() . ($rc->isVariadic() ? '...' : '');
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($parameters->isEmpty()) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_merge($result, [
|
||||||
|
'parameters' => $parameters->implode(','),
|
||||||
|
]);
|
||||||
|
});
|
||||||
@@ -88,8 +88,19 @@ namespace PHPSTORM_META {
|
|||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<?php if (isset($expectedArguments)) : ?>
|
<?php if (isset($expectedArguments)) : ?>
|
||||||
<?php foreach ($expectedArguments as $function => $arguments) : ?>
|
<?php foreach ($expectedArguments as $arguments) : ?>
|
||||||
<?php foreach ($arguments as $index => $argumentSet) : ?>
|
<?php
|
||||||
|
$classes = isset($arguments['class']) ? (array) $arguments['class'] : [null];
|
||||||
|
$index = $arguments['index'] ?? 0;
|
||||||
|
$argumentSet = $arguments['argumentSet'];
|
||||||
|
$functions = [];
|
||||||
|
foreach ($classes as $class) {
|
||||||
|
foreach ((array) $arguments['method'] as $method) {
|
||||||
|
$functions[] = '\\' . ($class ? ltrim($class, '\\') . '::' : '') . $method . '()';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<?php foreach ($functions as $function) : ?>
|
||||||
expectedArguments(<?= $function ?>, <?= $index ?>, argumentsSet('<?= $argumentSet ?>'));
|
expectedArguments(<?= $function ?>, <?= $index ?>, argumentsSet('<?= $argumentSet ?>'));
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
+91
-30
@@ -12,6 +12,8 @@
|
|||||||
namespace Barryvdh\LaravelIdeHelper\Console;
|
namespace Barryvdh\LaravelIdeHelper\Console;
|
||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Factories;
|
use Barryvdh\LaravelIdeHelper\Factories;
|
||||||
|
use Dotenv\Parser\Entry;
|
||||||
|
use Dotenv\Parser\Parser;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Contracts\Config\Repository;
|
use Illuminate\Contracts\Config\Repository;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
@@ -68,9 +70,7 @@ class MetaCommand extends Command
|
|||||||
protected $configMethods = [
|
protected $configMethods = [
|
||||||
'\config()',
|
'\config()',
|
||||||
'\Illuminate\Config\Repository::get()',
|
'\Illuminate\Config\Repository::get()',
|
||||||
'\Illuminate\Config\Repository::set()',
|
|
||||||
'\Illuminate\Support\Facades\Config::get()',
|
'\Illuminate\Support\Facades\Config::get()',
|
||||||
'\Illuminate\Support\Facades\Config::set()',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $userMethods = [
|
protected $userMethods = [
|
||||||
@@ -202,59 +202,105 @@ class MetaCommand extends Command
|
|||||||
protected function getExpectedArgumentSets()
|
protected function getExpectedArgumentSets()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'auth' => $this->loadTemplate('auth')->keys()->filter()->toArray(),
|
||||||
'configs' => $this->loadTemplate('configs')->pluck('name')->filter()->toArray(),
|
'configs' => $this->loadTemplate('configs')->pluck('name')->filter()->toArray(),
|
||||||
|
'middleware' => $this->loadTemplate('middleware')->keys()->filter()->toArray(),
|
||||||
'routes' => $this->loadTemplate('routes')->pluck('name')->filter()->toArray(),
|
'routes' => $this->loadTemplate('routes')->pluck('name')->filter()->toArray(),
|
||||||
'views' => $this->loadTemplate('views')->pluck('key')->filter()->map(function ($value) {
|
'views' => $this->loadTemplate('views')->pluck('key')->filter()->map(function ($value) {
|
||||||
return (string) $value;
|
return (string) $value;
|
||||||
})->toArray(),
|
})->toArray(),
|
||||||
'translations' => $this->loadTemplate('translations')->filter()->keys()->toArray(),
|
'translations' => $this->loadTemplate('translations')->filter()->keys()->toArray(),
|
||||||
|
'env' => $this->getEnv(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getExpectedArguments()
|
protected function getExpectedArguments()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'\config()' => [
|
[
|
||||||
0 => 'configs',
|
'class' => '\Illuminate\Support\Facades\Gate',
|
||||||
|
'method' => [
|
||||||
|
'has',
|
||||||
|
'allows',
|
||||||
|
'denies',
|
||||||
|
'check',
|
||||||
|
'any',
|
||||||
|
'none',
|
||||||
|
'authorize',
|
||||||
|
'inspect',
|
||||||
],
|
],
|
||||||
'\Illuminate\Config\Repository::get()' => [
|
'argumentSet' => 'auth',
|
||||||
0 => 'configs',
|
|
||||||
],
|
],
|
||||||
'\Illuminate\Config\Repository::set()' => [
|
[
|
||||||
0 => 'configs',
|
'class' => ['\Illuminate\Support\Facades\Route', '\Illuminate\Support\Facades\Auth'],
|
||||||
|
'method' => ['can', 'cannot'],
|
||||||
|
'argumentSet' => 'auth',
|
||||||
],
|
],
|
||||||
'\Illuminate\Support\Facades\Config::get()' => [
|
[
|
||||||
0 => 'configs',
|
'method' => 'config',
|
||||||
|
'argumentSet' => 'configs',
|
||||||
],
|
],
|
||||||
'\Illuminate\Support\Facades\Config::set()' => [
|
[
|
||||||
0 => 'configs',
|
'class' => ['\Illuminate\Config\Repository', '\Illuminate\Support\Facades\Config'],
|
||||||
|
'method' => [
|
||||||
|
'get',
|
||||||
|
'getMany',
|
||||||
|
'set',
|
||||||
|
'string',
|
||||||
|
'integer',
|
||||||
|
'boolean',
|
||||||
|
'float',
|
||||||
|
'array',
|
||||||
|
'prepend',
|
||||||
|
'push',
|
||||||
],
|
],
|
||||||
'\route()' => [
|
'argumentSet' => 'configs',
|
||||||
0 => 'routes',
|
|
||||||
],
|
],
|
||||||
'\Illuminate\Support\Facades\Route::get()' => [
|
[
|
||||||
0 => 'routes',
|
'class' => ['\Illuminate\Support\Facades\Route', '\Illuminate\Routing\Router'],
|
||||||
|
'method' => ['middleware', 'withoutMiddleware'],
|
||||||
|
'argumentSet' => 'middleware',
|
||||||
],
|
],
|
||||||
'\Illuminate\Routing\Router::get()' => [
|
[
|
||||||
0 => 'routes',
|
'method' => ['route', 'to_route', 'signedRoute'],
|
||||||
|
'argumentSet' => 'routes',
|
||||||
],
|
],
|
||||||
'\view()' => [
|
[
|
||||||
0 => 'views',
|
'class' => [
|
||||||
|
'\Illuminate\Support\Facades\Redirect',
|
||||||
|
'\Illuminate\Support\Facades\URL',
|
||||||
|
'\Illuminate\Routing\Redirector',
|
||||||
|
'\Illuminate\Routing\UrlGenerator',
|
||||||
],
|
],
|
||||||
'\Illuminate\Support\Facades\View::make()' => [
|
'method' => ['route', 'signedRoute', 'temporarySignedRoute'],
|
||||||
0 => 'views',
|
'argumentSet' => 'routes',
|
||||||
],
|
],
|
||||||
'\Illuminate\View\Factory::make()' => [
|
[
|
||||||
0 => 'views',
|
'method' => 'view',
|
||||||
|
'argumentSet' => 'views',
|
||||||
],
|
],
|
||||||
'\__()' => [
|
[
|
||||||
0 => 'translations',
|
'class' => ['\Illuminate\Support\Facades\View', '\Illuminate\View\Factory'],
|
||||||
|
'method' => 'make',
|
||||||
|
'argumentSet' => 'views',
|
||||||
],
|
],
|
||||||
'\trans()' => [
|
[
|
||||||
0 => 'translations',
|
'method' => ['__', 'trans'],
|
||||||
|
'argumentSet' => 'translations',
|
||||||
],
|
],
|
||||||
'\Illuminate\Contracts\Translation\Translator::get()' => [
|
[
|
||||||
0 => 'translations',
|
'class' => ['\Illuminate\Contracts\Translation\Translator'],
|
||||||
|
'method' => ['get'],
|
||||||
|
'argumentSet' => 'translations',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'method' => 'env',
|
||||||
|
'argumentSet' => 'env',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'class' => '\Illuminate\Support\Env',
|
||||||
|
'method' => 'get',
|
||||||
|
'argumentSet' => 'env',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -290,6 +336,21 @@ class MetaCommand extends Command
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getEnv()
|
||||||
|
{
|
||||||
|
$envPath = base_path('.env');
|
||||||
|
if (!file_exists($envPath)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$parser = new Parser();
|
||||||
|
$entries = $parser->parse(file_get_contents($envPath));
|
||||||
|
|
||||||
|
return collect($entries)->map(function (Entry $entry) {
|
||||||
|
return $entry->getName();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove our custom autoloader that we pushed onto the autoload stack
|
* Remove our custom autoloader that we pushed onto the autoload stack
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user