mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
692b223e94 | ||
|
|
f321828778 | ||
|
|
6eb797f5ff | ||
|
|
604d327277 | ||
|
|
6ed5367f6b | ||
|
|
8c339bd6b0 | ||
|
|
52b9b52926 | ||
|
|
f909c82fcc | ||
|
|
e88c3669b7 | ||
|
|
5bd7eeda23 | ||
|
|
dae0b55bef | ||
|
|
3f9831c5cf | ||
|
|
2cc277440a | ||
|
|
14eab5ef84 | ||
|
|
c94012232f | ||
|
|
b9685a1f83 | ||
|
|
7bc74b1844 | ||
|
|
cfa0333446 | ||
|
|
5c6fa1d43f | ||
|
|
23db0e06ca | ||
|
|
52b3accd70 | ||
|
|
cc07cd3b2c | ||
|
|
3113f58f45 | ||
|
|
d00dc62ed6 | ||
|
|
073d90b791 | ||
|
|
5d4af73c29 | ||
|
|
39ffaa62f4 | ||
|
|
231e125821 | ||
|
|
f446326967 | ||
|
|
57dc033061 | ||
|
|
e2b59c6cb5 | ||
|
|
736f2f387e | ||
|
|
486d9d9c4d | ||
|
|
ac8b868261 | ||
|
|
c0eb7e2d7e | ||
|
|
89a17fc7b9 | ||
|
|
ec43d4e65b | ||
|
|
03cc70759b | ||
|
|
f94743fda5 | ||
|
|
3eabba3e5d | ||
|
|
f2de8d3c65 | ||
|
|
10e16a0bdc | ||
|
|
f135845100 | ||
|
|
3c54b17760 | ||
|
|
9a67d9132f | ||
|
|
bd33e05304 | ||
|
|
83bdb7acd7 | ||
|
|
4fc9c671e8 | ||
|
|
6c18c3f39a | ||
|
|
19aa77ac49 | ||
|
|
25ec6bd1ea | ||
|
|
1b608fc446 | ||
|
|
09055582af | ||
|
|
4cfcabb63d | ||
|
|
cbfd53e0f9 | ||
|
|
fd11d89fa7 | ||
|
|
7f335274bf | ||
|
|
c01769aebd |
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"providers": [
|
||||
"Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider"
|
||||
"Barryvdh\\LaravelIdeHelper\\IdeHelperServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
## Laravel IDE Helper Generator
|
||||
[](https://packagist.org/packages/barryvdh/laravel-ide-helper) [](https://packagist.org/packages/barryvdh/laravel-ide-helper)
|
||||
|
||||
### For Laravel 5, check the [2.0 branch](https://github.com/barryvdh/laravel-ide-helper)
|
||||
|
||||
### Complete phpDocs, directly from the source
|
||||
|
||||
_Checkout [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
|
||||
@@ -12,11 +14,27 @@ If you don't want to generate it, you can add a pre-generated file to the root f
|
||||
|
||||
Note: You do need CodeIntel for Sublime Text: https://github.com/SublimeCodeIntel/SublimeCodeIntel
|
||||
|
||||
### New: PhpStorm Meta for Container instances
|
||||
|
||||
It's possible to generate a PhpStorm meta file, to [add support for factory design pattern](https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata). For Laravel, this means we can make PhpStorm understand what kind of object we are resolving from the IoC Container. For example, `events` will return ann `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
|
||||
|
||||
php artisan ide-helper:meta
|
||||
|
||||
app('events')->fire();
|
||||
\App::make('events')->fire();
|
||||
|
||||
/** @var \Illuminate\Foundation\Application $app */
|
||||
$app->make('events')->fire();
|
||||
|
||||
Pre-generated example: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
|
||||
|
||||
> Note: You might need to restart PhpStorm and make sure `.phpstorm.meta.php` is indexed.
|
||||
|
||||
### Automatic phpDoc generation for Laravel Facades
|
||||
|
||||
Require this package in your composer.json and run composer update (or run `composer require barryvdh/laravel-ide-helper:1.*` directly):
|
||||
Require this package with composer using the following command:
|
||||
|
||||
"barryvdh/laravel-ide-helper": "1.*"
|
||||
composer require barryvdh/laravel-ide-helper ~1.11
|
||||
|
||||
After updating composer, add the ServiceProvider to the providers array in app/config/app.php
|
||||
|
||||
@@ -34,7 +52,7 @@ You can configure your composer.json to do this after each commit:
|
||||
"post-update-cmd":[
|
||||
"php artisan clear-compiled",
|
||||
"php artisan ide-helper:generate",
|
||||
"php artisan optimize",
|
||||
"php artisan optimize"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -50,7 +68,6 @@ You can use a in-memory sqlite driver, using the -M option.
|
||||
You can choose to include helper files. This is not enabled by default, but you can override this with the --helpers (-H) option.
|
||||
The Illuminate/Support/helpers.php is already set-up, but you can add/remove your own files in the config file.
|
||||
|
||||
|
||||
### Automatic phpDocs for Models
|
||||
|
||||
> **Note:** Since v1.10 you need to require `doctrine/dbal: ~2.3` in your own composer.json.
|
||||
|
||||
+14
-6
@@ -12,11 +12,11 @@ namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
class Alias
|
||||
{
|
||||
|
||||
protected $alias;
|
||||
protected $facade;
|
||||
protected $extends = null;
|
||||
protected $classType = 'class';
|
||||
protected $short;
|
||||
protected $namespace = '__root';
|
||||
protected $root = null;
|
||||
protected $classes = array();
|
||||
@@ -42,7 +42,6 @@ class Alias
|
||||
$facade = '\\' . ltrim($facade, '\\');
|
||||
$this->facade = $facade;
|
||||
|
||||
|
||||
$this->detectRoot();
|
||||
|
||||
if ((!$this->isTrait() && $this->root)) {
|
||||
@@ -54,8 +53,10 @@ class Alias
|
||||
$this->addClass($this->root);
|
||||
$this->detectNamespace();
|
||||
$this->detectClassType();
|
||||
|
||||
|
||||
|
||||
if($facade === '\Illuminate\Database\Eloquent\Model'){
|
||||
$this->usedMethods = array('decrement', 'increment');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +115,12 @@ class Alias
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the short name (without namespace)
|
||||
*/
|
||||
public function getShortName(){
|
||||
return $this->short;
|
||||
}
|
||||
/**
|
||||
* Get the namespace from the alias
|
||||
*
|
||||
@@ -145,6 +152,8 @@ class Alias
|
||||
$nsParts = explode('\\', $this->alias);
|
||||
$this->short = array_pop($nsParts);
|
||||
$this->namespace = implode('\\', $nsParts);
|
||||
}else{
|
||||
$this->short = $this->alias;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +193,6 @@ class Alias
|
||||
|
||||
//If it doesn't exist, skip it
|
||||
if (!class_exists($root) && !interface_exists($root)) {
|
||||
$this->error("Class $root is not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,7 +261,7 @@ class Alias
|
||||
if (!in_array($method->name, $this->usedMethods)) {
|
||||
// Only add the methods to the output when the root is not the same as the class.
|
||||
// And don't add the __*() methods
|
||||
if ($this->extends !== $class && $method->name !== '__clone') {
|
||||
if ($this->extends !== $class && substr($method->name, 0, 2) !== '__') {
|
||||
$this->methods[] = new Method($method, $this->alias, $reflection, $method->name, $this->interfaces);
|
||||
}
|
||||
$this->usedMethods[] = $method->name;
|
||||
|
||||
@@ -82,6 +82,14 @@ class GeneratorCommand extends Command
|
||||
);
|
||||
} else {
|
||||
$filename = $this->argument('filename');
|
||||
$format = $this->option('format');
|
||||
|
||||
// Strip the php extension
|
||||
if (substr($filename, -4, 4) == '.php') {
|
||||
$filename = substr($filename, 0, -4);
|
||||
}
|
||||
|
||||
$filename .= '.' . $format;
|
||||
|
||||
if ($this->option('memory')) {
|
||||
$this->useMemoryDriver();
|
||||
@@ -100,7 +108,7 @@ class GeneratorCommand extends Command
|
||||
}
|
||||
|
||||
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
|
||||
$content = $generator->generate();
|
||||
$content = $generator->generate($format);
|
||||
$written = $this->files->put($filename, $content);
|
||||
|
||||
if ($written !== false) {
|
||||
@@ -131,12 +139,11 @@ class GeneratorCommand extends Command
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
$filename = $this->config->get('laravel-ide-helper::filename');
|
||||
|
||||
return array(
|
||||
array(
|
||||
'filename',
|
||||
InputArgument::OPTIONAL,
|
||||
'The path to the helper file',
|
||||
$this->config->get('laravel-ide-helper::filename')
|
||||
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -148,7 +155,10 @@ class GeneratorCommand extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$format = $this->config->get('laravel-ide-helper::format');
|
||||
|
||||
return array(
|
||||
array('format', "F", InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format),
|
||||
array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
|
||||
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
|
||||
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Laravel IDE Helper Generator
|
||||
*
|
||||
* @author Barry vd. Heuvel <[email protected]>
|
||||
* @copyright 2015 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||
*/
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* A command to generate phpstorm meta data
|
||||
*
|
||||
* @author Barry vd. Heuvel <[email protected]>
|
||||
*/
|
||||
class MetaCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'ide-helper:meta';
|
||||
protected $filename = '.phpstorm.meta.php';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate metadata for PhpStorm';
|
||||
|
||||
/** @var \Illuminate\Filesystem\Filesystem */
|
||||
protected $files;
|
||||
|
||||
/** @var \Illuminate\View\Factory */
|
||||
protected $view;
|
||||
|
||||
protected $methods = array(
|
||||
'\Illuminate\Foundation\Application::make',
|
||||
'\Illuminate\Container\Container::make',
|
||||
'\App::make',
|
||||
'app',
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param \Illuminate\View\Factory $view
|
||||
*/
|
||||
public function __construct($files, $view) {
|
||||
$this->files = $files;
|
||||
$this->view = $view;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$filename = $this->option('filename');
|
||||
|
||||
$bindings = array();
|
||||
|
||||
foreach ($this->laravel->getBindings() as $abstract => $options) {
|
||||
try {
|
||||
$concrete = $this->laravel->make($abstract);
|
||||
if (is_object($concrete)) {
|
||||
$bindings[$abstract] = get_class($concrete);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
$this->error("Cannot make $abstract: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$content = $this->view->make('laravel-ide-helper::meta', array(
|
||||
'bindings' => $bindings,
|
||||
'methods' => $this->methods,
|
||||
))->render();
|
||||
|
||||
$written = $this->files->put($filename, $content);
|
||||
|
||||
if ($written !== false) {
|
||||
$this->info("A new meta file was written to $filename");
|
||||
} else {
|
||||
$this->error("The meta file could not be created at $filename");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $this->filename),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -150,8 +150,6 @@ class ModelsCommand extends Command
|
||||
if (in_array($name, $ignore)) {
|
||||
$this->comment("Ignoring model '$name'");
|
||||
continue;
|
||||
} else {
|
||||
$this->comment("Loading model '$name'");
|
||||
}
|
||||
$this->properties = array();
|
||||
$this->methods = array();
|
||||
@@ -159,31 +157,35 @@ class ModelsCommand extends Command
|
||||
try {
|
||||
// handle abstract classes, interfaces, ...
|
||||
$reflectionClass = new \ReflectionClass($name);
|
||||
if (!$reflectionClass->IsInstantiable()) {
|
||||
throw new \Exception($name . ' is not instanciable.');
|
||||
} elseif (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
|
||||
$this->comment("Class '$name' is not a model");
|
||||
|
||||
if (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$model = new $name();
|
||||
$this->comment("Loading model '$name'");
|
||||
|
||||
if (!$reflectionClass->IsInstantiable()) {
|
||||
throw new \Exception($name . ' is not instantiable.');
|
||||
}
|
||||
|
||||
$model = $this->laravel->make($name);
|
||||
|
||||
if ($hasDoctrine) {
|
||||
$this->getPropertiesFromTable($model);
|
||||
}
|
||||
|
||||
$this->getPropertiesFromMethods($model);
|
||||
$output .= $this->createPhpDocs($name);
|
||||
} catch (\Exception $e) {
|
||||
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
||||
}
|
||||
} else {
|
||||
$this->error("Class $name does not exist");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$hasDoctrine) {
|
||||
$this->error(
|
||||
"Warning: 'doctrine/dbal: ~2.3' is required to load database information. Please require that in your composer.json and run 'composer update'."
|
||||
'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. Please require that in your composer.json and run `composer update`.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -254,8 +256,8 @@ class ModelsCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->setProperty($name, $type, true, true);
|
||||
$comment = $column->getComment();
|
||||
$this->setProperty($name, $type, true, true, $comment);
|
||||
$this->setMethod(
|
||||
Str::camel("where_" . $name),
|
||||
'\Illuminate\Database\Query\Builder|\\' . get_class($model),
|
||||
@@ -331,9 +333,9 @@ class ModelsCommand extends Command
|
||||
$search = '$this->' . $relation . '(';
|
||||
if ($pos = stripos($code, $search)) {
|
||||
$code = substr($code, $pos + strlen($search));
|
||||
$arguments = explode(',', substr($code, 0, stripos($code, ')')));
|
||||
$arguments = explode(',', substr($code, 0, strpos($code, ');')));
|
||||
//Remove quotes, ensure 1 \ in front of the model
|
||||
$returnModel = "\\" . ltrim(trim($arguments[0], " \"'"), "\\");
|
||||
$returnModel = $this->getClassName($arguments[0], $model);
|
||||
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') {
|
||||
//Collection or array of models (because Collection is Arrayable)
|
||||
$this->setProperty(
|
||||
@@ -359,14 +361,16 @@ class ModelsCommand extends Command
|
||||
* @param string|null $type
|
||||
* @param bool|null $read
|
||||
* @param bool|null $write
|
||||
* @param string|null $comment
|
||||
*/
|
||||
protected function setProperty($name, $type = null, $read = null, $write = null)
|
||||
protected function setProperty($name, $type = null, $read = null, $write = null, $comment='')
|
||||
{
|
||||
if (!isset($this->properties[$name])) {
|
||||
$this->properties[$name] = array();
|
||||
$this->properties[$name]['type'] = 'mixed';
|
||||
$this->properties[$name]['read'] = false;
|
||||
$this->properties[$name]['write'] = false;
|
||||
$this->properties[$name]['comment'] = (string) $comment;
|
||||
}
|
||||
if ($type !== null) {
|
||||
$this->properties[$name]['type'] = $type;
|
||||
@@ -433,7 +437,7 @@ class ModelsCommand extends Command
|
||||
} else {
|
||||
$attr = 'property-read';
|
||||
}
|
||||
$tag = Tag::createInstance("@{$attr} {$property['type']} {$name}", $phpdoc);
|
||||
$tag = Tag::createInstance("@{$attr} {$property['type']} {$name} {$property['comment']}", $phpdoc);
|
||||
$phpdoc->appendTag($tag);
|
||||
}
|
||||
|
||||
@@ -442,7 +446,7 @@ class ModelsCommand extends Command
|
||||
continue;
|
||||
}
|
||||
$arguments = implode(', ', $method['arguments']);
|
||||
$tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments}) ", $phpdoc);
|
||||
$tag = Tag::createInstance("@method static {$method['type']} {$name}({$arguments})", $phpdoc);
|
||||
$phpdoc->appendTag($tag);
|
||||
}
|
||||
|
||||
@@ -507,4 +511,24 @@ class ModelsCommand extends Command
|
||||
return $paramsWithDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return string
|
||||
*/
|
||||
private function getClassName($className, $model)
|
||||
{
|
||||
// If the class name was resolved via get_class($this) or static::class
|
||||
if (strpos($className, 'get_class($this)') !== false || strpos($className, 'static::class') !== false) {
|
||||
return get_class($model);
|
||||
}
|
||||
|
||||
// If the class name was resolved via ::class (PHP 5.5+)
|
||||
if (strpos($className, '::class') !== false) {
|
||||
$end = -1 * strlen('::class');
|
||||
return substr($className, 0, $end);
|
||||
}
|
||||
|
||||
return "\\" . ltrim(trim($className, " \"'"), "\\") ;
|
||||
}
|
||||
}
|
||||
|
||||
+50
-11
@@ -50,15 +50,31 @@ class Generator
|
||||
$this->extra = array_merge($this->extra, $this->config->get('laravel-ide-helper::extra'));
|
||||
$this->magic = array_merge($this->magic, $this->config->get('laravel-ide-helper::magic'));
|
||||
$this->interfaces = array_merge($this->interfaces, $this->config->get('laravel-ide-helper::interfaces'));
|
||||
// Make all interface classes absolute
|
||||
foreach ($this->interfaces as &$interface) {
|
||||
$interface = '\\' . ltrim($interface, '\\');
|
||||
}
|
||||
$this->helpers = $helpers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the helper file contents;
|
||||
*
|
||||
* @param string $format The format to generate the helper in (php/json)
|
||||
* @return string;
|
||||
*/
|
||||
public function generate()
|
||||
public function generate($format = 'php')
|
||||
{
|
||||
// Check if the generator for this format exists
|
||||
$method = 'generate'.ucfirst($format).'Helper';
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
}
|
||||
|
||||
return $this->generatePhpHelper();
|
||||
}
|
||||
|
||||
public function generatePhpHelper()
|
||||
{
|
||||
$app = app();
|
||||
return $this->view->make('laravel-ide-helper::ide-helper')
|
||||
@@ -68,10 +84,37 @@ class Generator
|
||||
->render();
|
||||
}
|
||||
|
||||
public function generateJsonHelper()
|
||||
{
|
||||
$classes = array();
|
||||
foreach ($this->getNamespaces() as $aliases) {
|
||||
foreach($aliases as $alias) {
|
||||
$functions = array();
|
||||
foreach ($alias->getMethods() as $method) {
|
||||
$functions[$method->getName()] = '('. $method->getParamsWithDefault().')';
|
||||
}
|
||||
$classes[$alias->getAlias()] = array(
|
||||
'functions' => $functions,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$flags = JSON_FORCE_OBJECT;
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
$flags |= JSON_PRETTY_PRINT;
|
||||
}
|
||||
|
||||
return json_encode(array(
|
||||
'php' => array(
|
||||
'classes' => $classes,
|
||||
),
|
||||
), $flags);
|
||||
}
|
||||
|
||||
protected function detectDrivers()
|
||||
{
|
||||
try{
|
||||
if (class_exists('Cache')) {
|
||||
try{
|
||||
if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)) {
|
||||
$class = get_class(\Auth::driver());
|
||||
$this->extra['Auth'] = array($class);
|
||||
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
|
||||
@@ -79,7 +122,7 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('DB')) {
|
||||
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
|
||||
$class = get_class(\DB::connection());
|
||||
$this->extra['DB'] = array($class);
|
||||
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
|
||||
@@ -87,7 +130,7 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('Cache')) {
|
||||
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
|
||||
$driver = get_class(\Cache::driver());
|
||||
$store = get_class(\Cache::getStore());
|
||||
$this->extra['Cache'] = array($driver, $store);
|
||||
@@ -96,7 +139,7 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('Queue')) {
|
||||
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
|
||||
$class = get_class(\Queue::connection());
|
||||
$this->extra['Queue'] = array($class);
|
||||
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
|
||||
@@ -104,17 +147,13 @@ class Generator
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
try{
|
||||
if (class_exists('SSH')){
|
||||
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)){
|
||||
$class = get_class(\SSH::connection());
|
||||
$this->extra['SSH'] = array($class);
|
||||
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
|
||||
}
|
||||
}catch (\Exception $e) {}
|
||||
|
||||
// Make all interface classes absolute
|
||||
foreach ($this->interfaces as &$interface) {
|
||||
$interface = '\\' . ltrim($interface, '\\');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Console\Generator2Command;
|
||||
Use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
|
||||
class IdeHelperServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -53,8 +53,14 @@ class IdeHelperServiceProvider extends ServiceProvider
|
||||
return new ModelsCommand();
|
||||
}
|
||||
);
|
||||
|
||||
$this->app['command.ide-helper.meta'] = $this->app->share(
|
||||
function ($app) {
|
||||
return new MetaCommand($app['files'], $app['view']);
|
||||
}
|
||||
);
|
||||
|
||||
$this->commands('command.ide-helper.generate', 'command.ide-helper.models');
|
||||
$this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,5 +72,37 @@ class IdeHelperServiceProvider extends ServiceProvider
|
||||
{
|
||||
return array('command.ide-helper.generate', 'command.ide-helper.models');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the package's component namespaces.
|
||||
*
|
||||
* @param string $package
|
||||
* @param string $namespace
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function package($package, $namespace = null, $path = null)
|
||||
{
|
||||
|
||||
// Is it possible to register the config?
|
||||
if (method_exists($this->app['config'], 'package')) {
|
||||
$this->app['config']->package($package, $path.'/config', $namespace);
|
||||
} else {
|
||||
// Load the config for now..
|
||||
$config = $this->app['files']->getRequire($path .'/config/config.php');
|
||||
foreach($config as $key => $value){
|
||||
$this->app['config']->set($namespace.'::'.$key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// Register view files
|
||||
$appView = $this->app['path']."/views/packages/{$package}";
|
||||
if ($this->app['files']->isDirectory($appView))
|
||||
{
|
||||
$this->app['view']->addNamespace($namespace, $appView);
|
||||
}
|
||||
|
||||
$this->app['view']->addNamespace($namespace, $path.'/views');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+25
-14
@@ -52,9 +52,9 @@ class Method
|
||||
|
||||
//Normalize the description and inherit the docs from parents/interfaces
|
||||
try {
|
||||
$this->normalizeDescription();
|
||||
$this->normalizeParams();
|
||||
$this->normalizeReturn();
|
||||
$this->normalizeParams($this->phpdoc);
|
||||
$this->normalizeReturn($this->phpdoc);
|
||||
$this->normalizeDescription($this->phpdoc);
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
//Get the parameters, including formatted default values
|
||||
@@ -136,11 +136,12 @@ class Method
|
||||
/**
|
||||
* Get the description and get the inherited docs.
|
||||
*
|
||||
* @param DocBlock $phpdoc
|
||||
*/
|
||||
protected function normalizeDescription()
|
||||
protected function normalizeDescription(DocBlock $phpdoc)
|
||||
{
|
||||
//Get the short + long description from the DocBlock
|
||||
$description = $this->phpdoc->getText();
|
||||
$description = $phpdoc->getText();
|
||||
|
||||
//Loop through parents/interfaces, to fill in {@inheritdoc}
|
||||
if (strpos($description, '{@inheritdoc}') !== false) {
|
||||
@@ -148,14 +149,18 @@ class Method
|
||||
$inheritDescription = $inheritdoc->getText();
|
||||
|
||||
$description = str_replace('{@inheritdoc}', $inheritDescription, $description);
|
||||
$this->phpdoc->setText($description);
|
||||
$phpdoc->setText($description);
|
||||
|
||||
$this->normalizeParams($inheritdoc);
|
||||
$this->normalizeReturn($inheritdoc);
|
||||
|
||||
//Add the tags that are inherited
|
||||
$inheritTags = $inheritdoc->getTags();
|
||||
if ($inheritTags) {
|
||||
/** @var Tag $tag */
|
||||
foreach ($inheritTags as $tag) {
|
||||
$tag->setDocBlock();
|
||||
$this->phpdoc->appendTag($tag);
|
||||
$phpdoc->appendTag($tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,11 +168,13 @@ class Method
|
||||
|
||||
/**
|
||||
* Normalize the parameters
|
||||
*
|
||||
* @param DocBlock $phpdoc
|
||||
*/
|
||||
protected function normalizeParams()
|
||||
protected function normalizeParams(DocBlock $phpdoc)
|
||||
{
|
||||
//Get the return type and adjust them for beter autocomplete
|
||||
$paramTags = $this->phpdoc->getTagsByName('param');
|
||||
$paramTags = $phpdoc->getTagsByName('param');
|
||||
if ($paramTags) {
|
||||
/** @var ParamTag $tag */
|
||||
foreach($paramTags as $tag){
|
||||
@@ -184,11 +191,13 @@ class Method
|
||||
|
||||
/**
|
||||
* Normalize the return tag (make full namespace, replace interfaces)
|
||||
*
|
||||
* @param DocBlock $phpdoc
|
||||
*/
|
||||
protected function normalizeReturn()
|
||||
protected function normalizeReturn(DocBlock $phpdoc)
|
||||
{
|
||||
//Get the return type and adjust them for beter autocomplete
|
||||
$returnTags = $this->phpdoc->getTagsByName('return');
|
||||
$returnTags = $phpdoc->getTagsByName('return');
|
||||
if ($returnTags) {
|
||||
/** @var ReturnTag $tag */
|
||||
$tag = reset($returnTags);
|
||||
@@ -252,7 +261,7 @@ class Method
|
||||
$paramStr = '$' . $param->getName();
|
||||
$params[] = $paramStr;
|
||||
if ($param->isOptional()) {
|
||||
$default = $param->getDefaultValue();
|
||||
$default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
|
||||
if (is_bool($default)) {
|
||||
$default = $default ? 'true' : 'false';
|
||||
} elseif (is_array($default)) {
|
||||
@@ -275,7 +284,7 @@ class Method
|
||||
|
||||
/**
|
||||
* @param \ReflectionMethod $reflectionMethod
|
||||
* @return string
|
||||
* @return DocBlock
|
||||
*/
|
||||
protected function getInheritDoc($reflectionMethod)
|
||||
{
|
||||
@@ -288,7 +297,9 @@ class Method
|
||||
$method = $reflectionMethod->getPrototype();
|
||||
}
|
||||
if ($method) {
|
||||
$phpdoc = new DocBlock($method);
|
||||
$namespace = $method->getDeclaringClass()->getNamespaceName();
|
||||
$phpdoc = new DocBlock($method, new Context($namespace));
|
||||
|
||||
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
|
||||
//Not at the end yet, try another parent/interface..
|
||||
return $this->getInheritDoc($method);
|
||||
|
||||
+19
-5
@@ -1,17 +1,20 @@
|
||||
<?php
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filename
|
||||
| Filename & Format
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The default path to the helper file
|
||||
| The default filename (without extension) and the format (php or json)
|
||||
|
|
||||
*/
|
||||
|
||||
'filename' => '_ide_helper.php',
|
||||
'filename' => '_ide_helper',
|
||||
'format' => 'php',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -71,8 +74,19 @@ return array(
|
||||
'emergency' => 'Monolog\Logger::addEmergency',
|
||||
)
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Interface implementations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These interfaces will be replaced with the implementing class. Some interfaces
|
||||
| are detected by the helpers, others can be listed below.
|
||||
|
|
||||
*/
|
||||
|
||||
'interfaces' => array(
|
||||
'\Illuminate\Auth\UserInterface' => '\User',
|
||||
'\Illuminate\Auth\UserInterface' => Config::get('auth.model', 'User'),
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
@@ -16,10 +16,10 @@ namespace <?= $namespace == '__root' ? '' : $namespace ?>{
|
||||
<?php endif; ?>
|
||||
<?php foreach($aliases as $alias): ?>
|
||||
|
||||
<?= $alias->getClassType() ?> <?= $alias->getAlias() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
|
||||
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
|
||||
<?php foreach($alias->getMethods() as $method): ?>
|
||||
|
||||
<?= trim($method->getDocComment()) ?>
|
||||
<?= trim($method->getDocComment(' ')) ?>
|
||||
|
||||
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>){<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?= '<?php' ?> namespace PHPSTORM_META {
|
||||
|
||||
/**
|
||||
* PhpStorm Meta file, to provide autocomplete information for PhpStorm
|
||||
* Generated on <?= date("Y-m-d") ?>.
|
||||
*
|
||||
* @author Barry vd. Heuvel <[email protected]>
|
||||
* @see https://github.com/barryvdh/laravel-ide-helper
|
||||
* @noinspection PhpUnusedLocalVariableInspection
|
||||
* @noinspection PhpIllegalArrayKeyTypeInspection
|
||||
*/
|
||||
$STATIC_METHOD_TYPES = [
|
||||
<?php foreach($methods as $method): ?>
|
||||
<?= $method ?>('') => [
|
||||
<?php foreach($bindings as $abstract => $class): ?>
|
||||
'<?= $abstract ?>' instanceof \<?= $class ?>,
|
||||
<?php endforeach ?> ],
|
||||
<?php endforeach ?>
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user