mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25c8de637d | ||
|
|
5a841a209d | ||
|
|
56660cab84 | ||
|
|
555d3e3700 | ||
|
|
963ead0a01 | ||
|
|
8c306035aa | ||
|
|
f1e93f042d | ||
|
|
5280b47750 | ||
|
|
525733122e | ||
|
|
a7fc2ec489 | ||
|
|
8caca941b3 | ||
|
|
e96943fe6f | ||
|
|
df3ecb2843 |
+4
-4
@@ -11,9 +11,9 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4.0",
|
"php": ">=5.4.0",
|
||||||
"illuminate/support": "^5.0,<5.4",
|
"illuminate/support": "^5.0,<5.5",
|
||||||
"illuminate/console": "^5.0,<5.4",
|
"illuminate/console": "^5.0,<5.5",
|
||||||
"illuminate/filesystem": "^5.0,<5.4",
|
"illuminate/filesystem": "^5.0,<5.5",
|
||||||
"barryvdh/reflection-docblock": "^2.0.4",
|
"barryvdh/reflection-docblock": "^2.0.4",
|
||||||
"symfony/class-loader": "^2.3|^3.0"
|
"symfony/class-loader": "^2.3|^3.0"
|
||||||
},
|
},
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "2.2-dev"
|
"dev-master": "2.3-dev"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,6 +151,18 @@ php artisan ide-helper:models --ignore="Post,User"
|
|||||||
|
|
||||||
Note: With namespaces, wrap your model name in " signs: `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
Note: With namespaces, wrap your model name in " signs: `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
||||||
|
|
||||||
|
### Automatic phpDocs generation for Laravel Fluent methods
|
||||||
|
If you need phpDocs support for Fluent methods in migration, for example
|
||||||
|
```php
|
||||||
|
$table->string(“somestring”)->nullable()->index();
|
||||||
|
```
|
||||||
|
After publishing vendor, simply change the `include_fluent` line your `config/ide-helper.php` file into:
|
||||||
|
```php
|
||||||
|
'include_fluent' => true,
|
||||||
|
```
|
||||||
|
And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE now.
|
||||||
|
|
||||||
|
|
||||||
## PhpStorm Meta for Container instances
|
## 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 an `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
|
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 an `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
|
||||||
@@ -177,7 +189,7 @@ Pre-generated example: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
|
|||||||
|
|
||||||
## Lumen Install
|
## Lumen Install
|
||||||
|
|
||||||
This pacakges is focused on Laravel development, but it can also be used in Lumen with some workarounds. Because Lumen works a little different, as it is like a barebone version of Laravel and the main configuration parameters are instead located in `bootstrap/app.php`, some arreglements must be made.
|
This package is focused on Laravel development, but it can also be used in Lumen with some workarounds. Because Lumen works a little different, as it is like a barebone version of Laravel and the main configuration parameters are instead located in `bootstrap/app.php`, some alterations must be made.
|
||||||
|
|
||||||
#### Enabling Facades
|
#### Enabling Facades
|
||||||
|
|
||||||
@@ -205,8 +217,7 @@ if ($app->environment() !== 'production') {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
After that, Laravel IDE Helper should work correctly. During the generation process, the script may throw exceptions saying that some Classes doesn't exist or there are some undefined indexes. This is normal, as Lumen has some default packages stripped away, like Cookies, Storage and Session. If you plan to add these packages, you will have to add them manually and create additional
|
After that, Laravel IDE Helper should work correctly. During the generation process, the script may throw exceptions saying that some Class(s) doesn't exist or there are some undefined indexes. This is normal, as Lumen has some default packages stripped away, like Cookies, Storage and Session. If you plan to add these packages, you will have to add them manually and create additional Facades if needed.
|
||||||
Facades if needed.
|
|
||||||
|
|
||||||
#### Adding Additional Facades
|
#### Adding Additional Facades
|
||||||
|
|
||||||
|
|||||||
+20
-11
@@ -7,21 +7,22 @@
|
|||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
* @see https://github.com/barryvdh/laravel-ide-helper
|
* @see https://github.com/barryvdh/laravel-ide-helper
|
||||||
*/
|
*/
|
||||||
|
namespace {
|
||||||
|
exit("This file should not be included, only analyzed by your IDE");
|
||||||
|
}
|
||||||
|
|
||||||
<?php foreach($namespaces as $namespace => $aliases): ?>
|
<?php foreach($namespaces as $namespace => $aliases): ?>
|
||||||
namespace <?= $namespace == '__root' ? '' : $namespace ?>{
|
<?php if ($namespace == '\Illuminate\Database\Eloquent'): continue; endif; ?>
|
||||||
<?php if($namespace == '__root'): ?>
|
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||||
exit("This file should not be included, only analyzed by your IDE");
|
|
||||||
<?= $helpers ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php foreach($aliases as $alias): ?>
|
<?php foreach($aliases as $alias): ?>
|
||||||
|
|
||||||
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
|
<?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
|
||||||
<?php foreach($alias->getMethods() as $method): ?>
|
<?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()): ?>
|
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
|
||||||
|
{<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>
|
||||||
|
|
||||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -31,13 +32,21 @@ namespace <?= $namespace == '__root' ? '' : $namespace ?>{
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
<?= $helpers ?>
|
||||||
|
|
||||||
|
<?php foreach($namespaces as $namespace => $aliases): ?>
|
||||||
|
<?php foreach($aliases as $alias): ?>
|
||||||
|
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> extends <?= $alias->getExtends() ?> {}
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
}
|
||||||
|
|
||||||
<?php if($include_fluent): ?>
|
<?php if($include_fluent): ?>
|
||||||
namespace Illuminate\Support {
|
namespace Illuminate\Support {
|
||||||
@@ -51,11 +60,11 @@ namespace Illuminate\Support {
|
|||||||
* @method Fluent default(mixed $value) Add the default modifier
|
* @method Fluent default(mixed $value) Add the default modifier
|
||||||
* @method Fluent first() Select first row
|
* @method Fluent first() Select first row
|
||||||
* @method Fluent index(string $name = null) Add the in dex clause
|
* @method Fluent index(string $name = null) Add the in dex clause
|
||||||
* @method Fluent on(string $column) `on` of a foreign key
|
* @method Fluent on(string $table) `on` of a foreign key
|
||||||
* @method Fluent onDelete(string $action) `on delete` of a foreign key
|
* @method Fluent onDelete(string $action) `on delete` of a foreign key
|
||||||
* @method Fluent onUpdate(string $action) `on update` of a foreign key
|
* @method Fluent onUpdate(string $action) `on update` of a foreign key
|
||||||
* @method Fluent primary() Add the primary key modifier
|
* @method Fluent primary() Add the primary key modifier
|
||||||
* @method Fluent references(string $table) `references` of a foreign key
|
* @method Fluent references(string $column) `references` of a foreign key
|
||||||
* @method Fluent nullable() Add the nullable modifier
|
* @method Fluent nullable() Add the nullable modifier
|
||||||
* @method Fluent unique(string $name = null) Add unique index clause
|
* @method Fluent unique(string $name = null) Add unique index clause
|
||||||
* @method Fluent unsigned() Add the unsigned modifier
|
* @method Fluent unsigned() Add the unsigned modifier
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ class Alias
|
|||||||
protected $alias;
|
protected $alias;
|
||||||
protected $facade;
|
protected $facade;
|
||||||
protected $extends = null;
|
protected $extends = null;
|
||||||
|
protected $extendsClass = null;
|
||||||
|
protected $extendsNamespace = null;
|
||||||
protected $classType = 'class';
|
protected $classType = 'class';
|
||||||
protected $short;
|
protected $short;
|
||||||
protected $namespace = '__root';
|
protected $namespace = '__root';
|
||||||
@@ -53,6 +55,7 @@ class Alias
|
|||||||
$this->addClass($this->root);
|
$this->addClass($this->root);
|
||||||
$this->detectNamespace();
|
$this->detectNamespace();
|
||||||
$this->detectClassType();
|
$this->detectClassType();
|
||||||
|
$this->detectExtendsNamespace();
|
||||||
|
|
||||||
if ($facade === '\Illuminate\Database\Eloquent\Model') {
|
if ($facade === '\Illuminate\Database\Eloquent\Model') {
|
||||||
$this->usedMethods = array('decrement', 'increment');
|
$this->usedMethods = array('decrement', 'increment');
|
||||||
@@ -105,6 +108,26 @@ class Alias
|
|||||||
return $this->extends;
|
return $this->extends;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the class short name which this alias extends
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public function getExtendsClass()
|
||||||
|
{
|
||||||
|
return $this->extendsClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the namespace of the class which this alias extends
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public function getExtendsNamespace()
|
||||||
|
{
|
||||||
|
return $this->extendsNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Alias by which this class is called
|
* Get the Alias by which this class is called
|
||||||
*
|
*
|
||||||
@@ -158,6 +181,18 @@ class Alias
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect the extends namespace
|
||||||
|
*/
|
||||||
|
protected function detectExtendsNamespace()
|
||||||
|
{
|
||||||
|
if (strpos($this->extends, '\\') !== false) {
|
||||||
|
$nsParts = explode('\\', $this->extends);
|
||||||
|
$this->extendsClass = array_pop($nsParts);
|
||||||
|
$this->extendsNamespace = implode('\\', $nsParts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect the class type
|
* Detect the class type
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -377,6 +377,7 @@ class ModelsCommand extends Command
|
|||||||
{
|
{
|
||||||
$methods = get_class_methods($model);
|
$methods = get_class_methods($model);
|
||||||
if ($methods) {
|
if ($methods) {
|
||||||
|
sort($methods);
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
if (Str::startsWith($method, 'get') && Str::endsWith(
|
if (Str::startsWith($method, 'get') && Str::endsWith(
|
||||||
$method,
|
$method,
|
||||||
@@ -569,6 +570,8 @@ class ModelsCommand extends Command
|
|||||||
$phpdoc->appendTag($tag);
|
$phpdoc->appendTag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($this->methods);
|
||||||
|
|
||||||
foreach ($this->methods as $name => $method) {
|
foreach ($this->methods as $name => $method) {
|
||||||
if (in_array($name, $methods)) {
|
if (in_array($name, $methods)) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
+1
-1
@@ -209,7 +209,7 @@ class Generator
|
|||||||
$alias->addClass($this->extra[$name]);
|
$alias->addClass($this->extra[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$namespace = $alias->getNamespace();
|
$namespace = $alias->getExtendsNamespace() ?: $alias->getNamespace();
|
||||||
if (!isset($namespaces[$namespace])) {
|
if (!isset($namespaces[$namespace])) {
|
||||||
$namespaces[$namespace] = array();
|
$namespaces[$namespace] = array();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,19 +54,22 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
$configPath = __DIR__ . '/../config/ide-helper.php';
|
$configPath = __DIR__ . '/../config/ide-helper.php';
|
||||||
$this->mergeConfigFrom($configPath, 'ide-helper');
|
$this->mergeConfigFrom($configPath, 'ide-helper');
|
||||||
|
|
||||||
$this->app['command.ide-helper.generate'] = $this->app->share(
|
$this->app->singleton(
|
||||||
|
'command.ide-helper.generate',
|
||||||
function ($app) {
|
function ($app) {
|
||||||
return new GeneratorCommand($app['config'], $app['files'], $app['view']);
|
return new GeneratorCommand($app['config'], $app['files'], $app['view']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->app['command.ide-helper.models'] = $this->app->share(
|
$this->app->singleton(
|
||||||
|
'command.ide-helper.models',
|
||||||
function ($app) {
|
function ($app) {
|
||||||
return new ModelsCommand($app['files']);
|
return new ModelsCommand($app['files']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->app['command.ide-helper.meta'] = $this->app->share(
|
$this->app->singleton(
|
||||||
|
'command.ide-helper.meta',
|
||||||
function ($app) {
|
function ($app) {
|
||||||
return new MetaCommand($app['files'], $app['view']);
|
return new MetaCommand($app['files'], $app['view']);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user