Compare commits

...
10 Commits
Author SHA1 Message Date
Zimin Cao 555d3e3700 Add documentation in readme.md for Laravel Fluent methods support (#446)
* Added readme for Fluent methods

* Add readme for Laravel Fluent methods
2017-02-13 20:20:12 +01:00
Tommi Finnilae 963ead0a01 Correct Fluent helper output (#445)
'references()' and 'on()' argument names were backwards
2017-02-13 12:53:06 +01:00
Florian Lefèvre 8c306035aa Fix facades fullpath autocomplete (#441)
* Add method to retrieve namespace of extended class

* Regroup classes by namespace of the class they extends

* Restore facades shortnames

* Fix classnames used for methods declaration
2017-02-13 12:52:36 +01:00
Barry vd. Heuvel f1e93f042d Update helper.php 2017-02-03 15:05:31 +01:00
Charles Peterson 5280b47750 readme spelling (#436)
just a couple spelling fixes for the readme file.
2017-02-01 09:59:19 +01:00
Florian Lefèvre 525733122e Add facades fullpath autocomplete (#437)
* Add method to retrieve namespace of extended class

* Regroup classes by namespace of the class they extends

* Restore facades shortnames
2017-02-01 07:21:31 +01:00
Django Eijgensteijn a7fc2ec489 Sorting model docs (#424) 2017-01-05 22:20:42 +01:00
Barry vd. Heuvel 8caca941b3 Update IdeHelperServiceProvider.php 2017-01-05 10:02:31 +01:00
Barry vd. Heuvel e96943fe6f Use singleton instead of share 2017-01-05 09:58:45 +01:00
Barry vd. Heuvel df3ecb2843 Update composer.json 2016-12-09 12:13:18 +01:00
7 changed files with 83 additions and 23 deletions
+3 -3
View File
@@ -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"
}, },
+14 -3
View File
@@ -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
+19 -11
View File
@@ -7,21 +7,21 @@
* @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 ?>{ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
<?php if($namespace == '__root'): ?>
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 +31,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 +59,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
+35
View File
@@ -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
*/ */
+3
View File
@@ -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
View File
@@ -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();
} }
+6 -3
View File
@@ -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']);
} }