diff --git a/src/Console/MetaCommand.php b/src/Console/MetaCommand.php new file mode 100644 index 0000000..b9d0753 --- /dev/null +++ b/src/Console/MetaCommand.php @@ -0,0 +1,97 @@ + + * @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 + */ +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; + + /** + * + * @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', ['bindings' => $bindings])->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), + ); + } +} diff --git a/src/IdeHelperServiceProvider.php b/src/IdeHelperServiceProvider.php index 074fd60..6af037c 100644 --- a/src/IdeHelperServiceProvider.php +++ b/src/IdeHelperServiceProvider.php @@ -52,8 +52,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'); } /** diff --git a/src/views/meta.php b/src/views/meta.php new file mode 100644 index 0000000..eeed9dd --- /dev/null +++ b/src/views/meta.php @@ -0,0 +1,24 @@ + namespace PHPSTORM_META { + +/** + * PhpStorm Meta file, to provide autocomplete information for PhpStorm + * Generated on . + * + * @author Barry vd. Heuvel + * @see https://github.com/barryvdh/laravel-ide-helper + */ + +/** @noinspection PhpUnusedLocalVariableInspection */ +/** @noinspection PhpIllegalArrayKeyTypeInspection */ +$STATIC_METHOD_TYPES = [ + \App::make('') => [ + $class): ?> + '' instanceof \, + ], + app('') => [ + $class): ?> + '' instanceof \, + ], +]; + +}