mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b91b959364 | ||
|
|
9b0fbb4467 | ||
|
|
6c8e847430 | ||
|
|
25b61c56fe | ||
|
|
428d32cebd | ||
|
|
51a72d7766 | ||
|
|
d200f2284b | ||
|
|
8faae38655 |
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: barryvdh
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||||
@@ -27,6 +27,18 @@ return array(
|
|||||||
|
|
||||||
'include_fluent' => false,
|
'include_fluent' => false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Factory Builders
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Set to true to generate factory generators for better factory()
|
||||||
|
| method auto-completion.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'include_factory_builders' => false,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Write Model Magic methods
|
| Write Model Magic methods
|
||||||
|
|||||||
@@ -7,6 +7,19 @@
|
|||||||
|
|
||||||
__For Laravel 4.x, check [version 1.11](https://github.com/barryvdh/laravel-ide-helper/tree/1.11)__
|
__For Laravel 4.x, check [version 1.11](https://github.com/barryvdh/laravel-ide-helper/tree/1.11)__
|
||||||
|
|
||||||
|
* [Complete phpDocs, directly from the source](#complete-phpdocs--directly-from-the-source)
|
||||||
|
* [Install](#install)
|
||||||
|
* [Automatic phpDoc generation for Laravel Facades](#automatic-phpdoc-generation-for-laravel-facades)
|
||||||
|
* [Automatic phpDocs for models](#automatic-phpdocs-for-models)
|
||||||
|
* [Automatic phpDocs generation for Laravel Fluent methods](#automatic-phpdocs-generation-for-laravel-fluent-methods)
|
||||||
|
* [Auto-completion for factory builders](#auto-completion-for-factory-builders)
|
||||||
|
- [PhpStorm Meta for Container instances](#phpstorm-meta-for-container-instances)
|
||||||
|
- [Lumen Install](#lumen-install)
|
||||||
|
+ [Enabling Facades](#enabling-facades)
|
||||||
|
+ [Adding the Service Provider](#adding-the-service-provider)
|
||||||
|
+ [Adding Additional Facades](#adding-additional-facades)
|
||||||
|
* [License](#license)
|
||||||
|
|
||||||
### Complete phpDocs, directly from the source
|
### Complete phpDocs, directly from the source
|
||||||
|
|
||||||
_Check out [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
|
_Check out [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
|
||||||
@@ -69,8 +82,8 @@ You can configure your composer.json to do this after each commit:
|
|||||||
"scripts":{
|
"scripts":{
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
|
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
|
||||||
"php artisan ide-helper:generate",
|
"@php artisan ide-helper:generate",
|
||||||
"php artisan ide-helper:meta"
|
"@php artisan ide-helper:meta"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
@@ -91,13 +104,6 @@ The `Illuminate/Support/helpers.php` is already set up, but you can add/remove y
|
|||||||
|
|
||||||
### Automatic phpDocs for models
|
### Automatic phpDocs for models
|
||||||
|
|
||||||
> You need to add `doctrine/dbal: ~2.3` to require-dev in your own composer.json to get database columns.
|
|
||||||
|
|
||||||
|
|
||||||
```bash
|
|
||||||
composer require --dev doctrine/dbal
|
|
||||||
```
|
|
||||||
|
|
||||||
If you don't want to write your properties yourself, you can use the command `php artisan ide-helper:models` to generate
|
If you don't want to write your properties yourself, you can use the command `php artisan ide-helper:models` to generate
|
||||||
phpDocs, based on table columns, relations and getters/setters. You can write the comments directly to your Model file, using the `--write (-W)` option. By default, you are asked to overwrite or write to a separate file (`_ide_helper_models.php`). You can force No with `--nowrite (-N)`.
|
phpDocs, based on table columns, relations and getters/setters. You can write the comments directly to your Model file, using the `--write (-W)` option. By default, you are asked to overwrite or write to a separate file (`_ide_helper_models.php`). You can force No with `--nowrite (-N)`.
|
||||||
Please make sure to backup your models, before writing the info.
|
Please make sure to backup your models, before writing the info.
|
||||||
@@ -163,6 +169,18 @@ After publishing vendor, simply change the `include_fluent` line your `config/id
|
|||||||
And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE.
|
And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE.
|
||||||
|
|
||||||
|
|
||||||
|
### Auto-completion for factory builders
|
||||||
|
|
||||||
|
If you would like the `factory()->create()` and `factory()->make()` methods to return the correct model class,
|
||||||
|
you can enable custom factory builders with the `include_factory_builders` line your `config/ide-helper.php` file.
|
||||||
|
|
||||||
|
```php
|
||||||
|
'include_factory_builders' => true,
|
||||||
|
```
|
||||||
|
|
||||||
|
For this to work, you must also publish the PhpStorm Meta file (see below).
|
||||||
|
|
||||||
|
|
||||||
## 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.
|
||||||
|
|||||||
@@ -105,3 +105,13 @@ namespace Illuminate\Support {
|
|||||||
class Fluent {}
|
class Fluent {}
|
||||||
}
|
}
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<?php foreach ($factories as $factory): ?>
|
||||||
|
namespace <?=$factory->getNamespaceName()?> {
|
||||||
|
/**
|
||||||
|
* @method \Illuminate\Database\Eloquent\Collection|<?=$factory->getShortName()?>[]|<?=$factory->getShortName()?> create($attributes = [])
|
||||||
|
* @method \Illuminate\Database\Eloquent\Collection|<?=$factory->getShortName()?>[]|<?=$factory->getShortName()?> make($attributes = [])
|
||||||
|
*/
|
||||||
|
class <?=$factory->getShortName()?>FactoryBuilder extends \Illuminate\Database\Eloquent\FactoryBuilder {}
|
||||||
|
}
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|||||||
@@ -20,6 +20,15 @@ namespace PHPSTORM_META {
|
|||||||
]));
|
]));
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?php if (count($factories)): ?>
|
||||||
|
override(\factory(0), map([
|
||||||
|
'' => '@FactoryBuilder',
|
||||||
|
<?php foreach($factories as $factory): ?>
|
||||||
|
'<?= $factory->getName() ?>' => \<?= $factory->getName() ?>FactoryBuilder::class,
|
||||||
|
<?php endforeach; ?>
|
||||||
|
]));
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
override(\Illuminate\Support\Arr::add(0), type(0));
|
override(\Illuminate\Support\Arr::add(0), type(0));
|
||||||
override(\Illuminate\Support\Arr::except(0), type(0));
|
override(\Illuminate\Support\Arr::except(0), type(0));
|
||||||
override(\Illuminate\Support\Arr::first(0), elementType(0));
|
override(\Illuminate\Support\Arr::first(0), elementType(0));
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Console;
|
namespace Barryvdh\LaravelIdeHelper\Console;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Factories;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@@ -77,6 +78,9 @@ class MetaCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
// Needs to run before exception handler is registered
|
||||||
|
$factories = $this->config->get('ide-helper.include_factory_builders') ? Factories::all() : [];
|
||||||
|
|
||||||
$this->registerClassAutoloadExceptions();
|
$this->registerClassAutoloadExceptions();
|
||||||
|
|
||||||
$bindings = array();
|
$bindings = array();
|
||||||
@@ -102,6 +106,7 @@ class MetaCommand extends Command
|
|||||||
$content = $this->view->make('meta', [
|
$content = $this->view->make('meta', [
|
||||||
'bindings' => $bindings,
|
'bindings' => $bindings,
|
||||||
'methods' => $this->methods,
|
'methods' => $this->methods,
|
||||||
|
'factories' => $factories,
|
||||||
])->render();
|
])->render();
|
||||||
|
|
||||||
$filename = $this->option('filename');
|
$filename = $this->option('filename');
|
||||||
|
|||||||
@@ -455,9 +455,16 @@ class ModelsCommand extends Command
|
|||||||
) {
|
) {
|
||||||
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
||||||
$reflection = new \ReflectionMethod($model, $method);
|
$reflection = new \ReflectionMethod($model, $method);
|
||||||
// php 7.x type or fallback to docblock
|
|
||||||
$type = (string) ($reflection->getReturnType() ?: $this->getReturnTypeFromDocBlock($reflection));
|
|
||||||
|
|
||||||
|
if ($returnType = $reflection->getReturnType()) {
|
||||||
|
$type = $returnType instanceof \ReflectionNamedType
|
||||||
|
? $returnType->getName()
|
||||||
|
: (string)$returnType;
|
||||||
|
} else {
|
||||||
|
// php 7.x type or fallback to docblock
|
||||||
|
$type = (string)$this->getReturnTypeFromDocBlock($reflection);
|
||||||
|
}
|
||||||
|
|
||||||
$file = new \SplFileObject($reflection->getFileName());
|
$file = new \SplFileObject($reflection->getFileName());
|
||||||
$file->seek($reflection->getStartLine() - 1);
|
$file->seek($reflection->getStartLine() - 1);
|
||||||
|
|
||||||
@@ -473,6 +480,7 @@ class ModelsCommand extends Command
|
|||||||
foreach (array(
|
foreach (array(
|
||||||
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
||||||
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
||||||
|
'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough',
|
||||||
'belongsToMany' => '\Illuminate\Database\Eloquent\Relations\BelongsToMany',
|
'belongsToMany' => '\Illuminate\Database\Eloquent\Relations\BelongsToMany',
|
||||||
'hasOne' => '\Illuminate\Database\Eloquent\Relations\HasOne',
|
'hasOne' => '\Illuminate\Database\Eloquent\Relations\HasOne',
|
||||||
'belongsTo' => '\Illuminate\Database\Eloquent\Relations\BelongsTo',
|
'belongsTo' => '\Illuminate\Database\Eloquent\Relations\BelongsTo',
|
||||||
@@ -730,7 +738,7 @@ class ModelsCommand extends Command
|
|||||||
if (is_bool($default)) {
|
if (is_bool($default)) {
|
||||||
$default = $default ? 'true' : 'false';
|
$default = $default ? 'true' : 'false';
|
||||||
} elseif (is_array($default)) {
|
} elseif (is_array($default)) {
|
||||||
$default = 'array()';
|
$default = '[]';
|
||||||
} elseif (is_null($default)) {
|
} elseif (is_null($default)) {
|
||||||
$default = 'null';
|
$default = 'null';
|
||||||
} elseif (is_int($default)) {
|
} elseif (is_int($default)) {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Database\Eloquent\Factory;
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
|
class Factories
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function all()
|
||||||
|
{
|
||||||
|
$factories = [];
|
||||||
|
|
||||||
|
$factory = app(Factory::class);
|
||||||
|
|
||||||
|
$definitions = (new ReflectionClass(Factory::class))->getProperty('definitions');
|
||||||
|
$definitions->setAccessible(true);
|
||||||
|
|
||||||
|
foreach ($definitions->getValue($factory) as $factory_target => $config) {
|
||||||
|
try {
|
||||||
|
$factories[] = new ReflectionClass($factory_target);
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $factories;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,7 @@ class Generator
|
|||||||
->with('helpers', $this->helpers)
|
->with('helpers', $this->helpers)
|
||||||
->with('version', $app->version())
|
->with('version', $app->version())
|
||||||
->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))
|
->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))
|
||||||
|
->with('factories', $this->config->get('ide-helper.include_factory_builders') ? Factories::all() : [])
|
||||||
->render();
|
->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -321,7 +321,7 @@ class Method
|
|||||||
if (is_bool($default)) {
|
if (is_bool($default)) {
|
||||||
$default = $default ? 'true' : 'false';
|
$default = $default ? 'true' : 'false';
|
||||||
} elseif (is_array($default)) {
|
} elseif (is_array($default)) {
|
||||||
$default = 'array()';
|
$default = '[]';
|
||||||
} elseif (is_null($default)) {
|
} elseif (is_null($default)) {
|
||||||
$default = 'null';
|
$default = 'null';
|
||||||
} elseif (is_int($default)) {
|
} elseif (is_int($default)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user