mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
387efb9b42 | ||
|
|
28f0ac3781 | ||
|
|
ea6d6d0105 | ||
|
|
01320a48e3 | ||
|
|
fedcb57295 | ||
|
|
ce72ff4663 | ||
|
|
cb6f52f4d6 | ||
|
|
55c9bfc33b | ||
|
|
a9ea231679 | ||
|
|
2b1273c45e | ||
|
|
08d39c125f |
+5
-5
@@ -11,15 +11,15 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4.0",
|
"php": ">=5.4.0",
|
||||||
"illuminate/support": "^5.0,<5.6",
|
"illuminate/support": "^5.0,<5.7",
|
||||||
"illuminate/console": "^5.0,<5.6",
|
"illuminate/console": "^5.0,<5.7",
|
||||||
"illuminate/filesystem": "^5.0,<5.6",
|
"illuminate/filesystem": "^5.0,<5.7",
|
||||||
"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"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"illuminate/config": "^5.0,<5.6",
|
"illuminate/config": "^5.0,<5.7",
|
||||||
"illuminate/view": "^5.0,<5.6",
|
"illuminate/view": "^5.0,<5.7",
|
||||||
"phpunit/phpunit" : "4.*",
|
"phpunit/phpunit" : "4.*",
|
||||||
"scrutinizer/ocular": "~1.1",
|
"scrutinizer/ocular": "~1.1",
|
||||||
"squizlabs/php_codesniffer": "~2.3",
|
"squizlabs/php_codesniffer": "~2.3",
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ return array(
|
|||||||
|
|
||||||
'filename' => '_ide_helper',
|
'filename' => '_ide_helper',
|
||||||
'format' => 'php',
|
'format' => 'php',
|
||||||
|
|
||||||
|
'meta_filename' => '.phpstorm.meta.php',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ If you don't want to generate it, you can add a pre-generated file to the root f
|
|||||||
* Generated version for Lumen: https://gist.github.com/barryvdh/be17164b0ad51f832f20
|
* Generated version for Lumen: https://gist.github.com/barryvdh/be17164b0ad51f832f20
|
||||||
* Generated Phpstorm Meta file: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
|
* Generated Phpstorm Meta file: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
|
||||||
|
|
||||||
Note: You do need CodeIntel for Sublime Text: https://github.com/SublimeCodeIntel/SublimeCodeIntel
|
Note: You do need CodeComplice for Sublime Text: https://github.com/spectacles/CodeComplice
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
|
|
||||||
@@ -151,9 +151,9 @@ php artisan ide-helper:models --ignore="Post,User"
|
|||||||
|
|
||||||
Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
||||||
|
|
||||||
For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add
|
For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add
|
||||||
```php
|
```php
|
||||||
/** @mixin \Eloquent */
|
/** @mixin \Eloquent */
|
||||||
```
|
```
|
||||||
for your model class.
|
for your model class.
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ After publishing vendor, simply change the `include_fluent` line your `config/id
|
|||||||
```php
|
```php
|
||||||
'include_fluent' => true,
|
'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.
|
And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE.
|
||||||
|
|
||||||
|
|
||||||
## PhpStorm Meta for Container instances
|
## PhpStorm Meta for Container instances
|
||||||
|
|||||||
@@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper file for Laravel 5, to provide autocomplete information to your IDE
|
* A helper file for Laravel 5, to provide autocomplete information to your IDE
|
||||||
* Generated for Laravel <?= $version ?> on <?= date("Y-m-d") ?>.
|
* Generated for Laravel <?= $version ?> on <?= date("Y-m-d H:i:s") ?>.
|
||||||
|
*
|
||||||
|
* This file should not be included in your code, only analyzed by your IDE!
|
||||||
*
|
*
|
||||||
* @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_by_extends_ns as $namespace => $aliases): ?>
|
<?php foreach($namespaces_by_extends_ns as $namespace => $aliases): ?>
|
||||||
<?php if ($namespace == '\Illuminate\Database\Eloquent'): continue; endif; ?>
|
<?php if ($namespace == '\Illuminate\Database\Eloquent'): continue; endif; ?>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace PHPSTORM_META {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* PhpStorm Meta file, to provide autocomplete information for PhpStorm
|
* PhpStorm Meta file, to provide autocomplete information for PhpStorm
|
||||||
* Generated on <?= date("Y-m-d") ?>.
|
* Generated on <?= date("Y-m-d H:i:s") ?>.
|
||||||
*
|
*
|
||||||
* @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
|
||||||
@@ -13,7 +13,7 @@ namespace PHPSTORM_META {
|
|||||||
override(<?= $method ?>, map([
|
override(<?= $method ?>, map([
|
||||||
'' => '@',
|
'' => '@',
|
||||||
<?php foreach($bindings as $abstract => $class): ?>
|
<?php foreach($bindings as $abstract => $class): ?>
|
||||||
'<?= $abstract ?>' => <?= $class ?>::class,
|
'<?= $abstract ?>' => \<?= $class ?>::class,
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
]));
|
]));
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -46,5 +46,6 @@ namespace PHPSTORM_META {
|
|||||||
override(\head(0), elementType(0));
|
override(\head(0), elementType(0));
|
||||||
override(\last(0), elementType(0));
|
override(\last(0), elementType(0));
|
||||||
override(\with(0), type(0));
|
override(\with(0), type(0));
|
||||||
|
override(\tap(0), type(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Laravel IDE Helper Generator - Eloquent Model Mixin
|
||||||
|
*
|
||||||
|
* @author Charles A. Peterson <[email protected]>
|
||||||
|
* @copyright 2017 Charles A. Peterson / 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 Barryvdh\LaravelIdeHelper\Eloquent;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A command to add \Eloquent mixin to Eloquent\Model
|
||||||
|
*
|
||||||
|
* @author Charles A. Peterson <[email protected]>
|
||||||
|
*/
|
||||||
|
class EloquentCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The console command name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $name = 'ide-helper:eloquent';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Filesystem $files
|
||||||
|
*/
|
||||||
|
protected $files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Add \Eloquent helper to \Eloquent\Model';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Filesystem $files
|
||||||
|
*/
|
||||||
|
public function __construct(Filesystem $files)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->files = $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
Eloquent::writeEloquentModelHelper($this, $this->files);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Console;
|
namespace Barryvdh\LaravelIdeHelper\Console;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Eloquent;
|
||||||
use Barryvdh\LaravelIdeHelper\Generator;
|
use Barryvdh\LaravelIdeHelper\Generator;
|
||||||
use Illuminate\Config\Repository as ConfigRepository;
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
use Illuminate\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
@@ -74,7 +74,7 @@ class GeneratorCommand extends Command
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function fire()
|
public function handle()
|
||||||
{
|
{
|
||||||
if (file_exists(base_path() . '/vendor/compiled.php') ||
|
if (file_exists(base_path() . '/vendor/compiled.php') ||
|
||||||
file_exists(base_path() . '/bootstrap/cache/compiled.php') ||
|
file_exists(base_path() . '/bootstrap/cache/compiled.php') ||
|
||||||
@@ -115,6 +115,7 @@ class GeneratorCommand extends Command
|
|||||||
|
|
||||||
if ($written !== false) {
|
if ($written !== false) {
|
||||||
$this->info("A new helper file was written to $filename");
|
$this->info("A new helper file was written to $filename");
|
||||||
|
Eloquent::writeEloquentModelHelper($this, $this->files);
|
||||||
} else {
|
} else {
|
||||||
$this->error("The helper file could not be created at $filename");
|
$this->error("The helper file could not be created at $filename");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class MetaCommand extends Command
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $name = 'ide-helper:meta';
|
protected $name = 'ide-helper:meta';
|
||||||
protected $filename = '.phpstorm.meta.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -43,6 +42,9 @@ class MetaCommand extends Command
|
|||||||
/** @var \Illuminate\Contracts\View\Factory */
|
/** @var \Illuminate\Contracts\View\Factory */
|
||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
|
/** @var \Illuminate\Contracts\Config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
protected $methods = [
|
protected $methods = [
|
||||||
'new \Illuminate\Contracts\Container\Container',
|
'new \Illuminate\Contracts\Container\Container',
|
||||||
'\Illuminate\Contracts\Container\Container::make(0)',
|
'\Illuminate\Contracts\Container\Container::make(0)',
|
||||||
@@ -57,11 +59,13 @@ class MetaCommand extends Command
|
|||||||
*
|
*
|
||||||
* @param \Illuminate\Contracts\Filesystem\Filesystem $files
|
* @param \Illuminate\Contracts\Filesystem\Filesystem $files
|
||||||
* @param \Illuminate\Contracts\View\Factory $view
|
* @param \Illuminate\Contracts\View\Factory $view
|
||||||
|
* @param \Illuminate\Contracts\Config $config
|
||||||
*/
|
*/
|
||||||
public function __construct($files, $view)
|
public function __construct($files, $view, $config)
|
||||||
{
|
{
|
||||||
$this->files = $files;
|
$this->files = $files;
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
|
$this->config = $config;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +74,7 @@ class MetaCommand extends Command
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function fire()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->registerClassAutoloadExceptions();
|
$this->registerClassAutoloadExceptions();
|
||||||
|
|
||||||
@@ -138,8 +142,10 @@ class MetaCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
|
$filename = $this->config->get('ide-helper.meta_filename');
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $this->filename),
|
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class ModelsCommand extends Command
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function fire()
|
public function handle()
|
||||||
{
|
{
|
||||||
$filename = $this->option('filename');
|
$filename = $this->option('filename');
|
||||||
$this->write = $this->option('write');
|
$this->write = $this->option('write');
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Laravel IDE Helper to add \Eloquent mixin to Eloquent\Model
|
||||||
|
*
|
||||||
|
* @author Charles A. Peterson <[email protected]>
|
||||||
|
*/
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Barryvdh\Reflection\DocBlock;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
class Eloquent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Write mixin helper to the Eloquent\Model
|
||||||
|
* This is needed since laravel/framework v5.4.29
|
||||||
|
*
|
||||||
|
* @param Command $command
|
||||||
|
* @param Filesystem $files
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function writeEloquentModelHelper(Command $command, Filesystem $files)
|
||||||
|
{
|
||||||
|
$class = 'Illuminate\Database\Eloquent\Model';
|
||||||
|
|
||||||
|
$reflection = new \ReflectionClass($class);
|
||||||
|
$namespace = $reflection->getNamespaceName();
|
||||||
|
$originalDoc = $reflection->getDocComment();
|
||||||
|
if (!$originalDoc) {
|
||||||
|
$command->info('Unexpected no document on ' . $class);
|
||||||
|
}
|
||||||
|
$phpdoc = new DocBlock($reflection, new Context($namespace));
|
||||||
|
|
||||||
|
$mixins = $phpdoc->getTagsByName('mixin');
|
||||||
|
foreach ($mixins as $m) {
|
||||||
|
if ($m->getContent() === '\Eloquent') {
|
||||||
|
$command->info('Tag Exists: @mixin \Eloquent in ' . $class);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the Eloquent mixin
|
||||||
|
$phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
|
||||||
|
|
||||||
|
$serializer = new DocBlockSerializer();
|
||||||
|
$serializer->getDocComment($phpdoc);
|
||||||
|
$docComment = $serializer->getDocComment($phpdoc);
|
||||||
|
|
||||||
|
$filename = $reflection->getFileName();
|
||||||
|
if ($filename) {
|
||||||
|
$contents = $files->get($filename);
|
||||||
|
if ($contents) {
|
||||||
|
$count = 0;
|
||||||
|
$contents = str_replace($originalDoc, $docComment, $contents, $count);
|
||||||
|
if ($count > 0) {
|
||||||
|
if ($files->put($filename, $contents)) {
|
||||||
|
$command->info('Wrote @mixin \Eloquent to ' . $filename);
|
||||||
|
} else {
|
||||||
|
$command->error('File write failed to ' . $filename);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$command->error('Content did not change ' . $contents);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$command->error('No file contents found ' . $filename);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$command->error('Filename not found ' . $class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,10 +10,11 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\View\Engines\EngineResolver;
|
use Illuminate\View\Engines\EngineResolver;
|
||||||
use Illuminate\View\Engines\PhpEngine;
|
use Illuminate\View\Engines\PhpEngine;
|
||||||
use Illuminate\View\Factory;
|
use Illuminate\View\Factory;
|
||||||
@@ -38,7 +39,7 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$viewPath = __DIR__.'/../resources/views';
|
$viewPath = __DIR__.'/../resources/views';
|
||||||
$this->loadViewsFrom($viewPath, 'ide-helper');
|
$this->loadViewsFrom($viewPath, 'ide-helper');
|
||||||
|
|
||||||
$configPath = __DIR__ . '/../config/ide-helper.php';
|
$configPath = __DIR__ . '/../config/ide-helper.php';
|
||||||
if (function_exists('config_path')) {
|
if (function_exists('config_path')) {
|
||||||
$publishPath = config_path('ide-helper.php');
|
$publishPath = config_path('ide-helper.php');
|
||||||
@@ -58,7 +59,7 @@ 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');
|
||||||
$localViewFactory = $this->createLocalViewFactory();
|
$localViewFactory = $this->createLocalViewFactory();
|
||||||
|
|
||||||
$this->app->singleton(
|
$this->app->singleton(
|
||||||
'command.ide-helper.generate',
|
'command.ide-helper.generate',
|
||||||
function ($app) use ($localViewFactory) {
|
function ($app) use ($localViewFactory) {
|
||||||
@@ -72,15 +73,27 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
return new ModelsCommand($app['files']);
|
return new ModelsCommand($app['files']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->app->singleton(
|
$this->app->singleton(
|
||||||
'command.ide-helper.meta',
|
'command.ide-helper.meta',
|
||||||
function ($app) use ($localViewFactory) {
|
function ($app) use ($localViewFactory) {
|
||||||
return new MetaCommand($app['files'], $localViewFactory);
|
return new MetaCommand($app['files'], $localViewFactory, $app['config']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
|
$this->app->singleton(
|
||||||
|
'command.ide-helper.eloquent',
|
||||||
|
function ($app) use ($localViewFactory) {
|
||||||
|
return new EloquentCommand($app['files']);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->commands(
|
||||||
|
'command.ide-helper.generate',
|
||||||
|
'command.ide-helper.models',
|
||||||
|
'command.ide-helper.meta',
|
||||||
|
'command.ide-helper.eloquent'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user