Compare commits

...
9 Commits
Author SHA1 Message Date
Barry vd. Heuvel 765a274c05 More methods 2015-03-16 14:26:28 +01:00
Barry vd. Heuvel b6a5262f3b TWeak meta methods 2015-03-16 14:14:57 +01:00
Barry vd. Heuvel d922d7e7ce Add actual command 2015-03-16 13:13:00 +01:00
Barry vd. Heuvel 89240e3ceb Add gist 2015-03-16 13:05:56 +01:00
Barry vd. Heuvel d9077b753c Note about missing classes. 2015-03-16 13:01:21 +01:00
Barry vd. Heuvel 683ed695a5 Fix views 2015-03-16 12:59:27 +01:00
Barry vd. Heuvel f8c4d4e77a Fix class imports 2015-03-16 12:52:48 +01:00
Barry vd. Heuvel b1a4494b1c Add note about meta file 2015-03-16 12:40:17 +01:00
Barry vd. Heuvel 70c06f5b37 Add meta command for phpstorm 2015-03-16 12:14:15 +01:00
4 changed files with 155 additions and 3 deletions
+15 -1
View File
@@ -14,6 +14,21 @@ If you don't want to generate it, you can add a pre-generated file to the root f
Note: You do need CodeIntel for Sublime Text: https://github.com/SublimeCodeIntel/SublimeCodeIntel Note: You do need CodeIntel for Sublime Text: https://github.com/SublimeCodeIntel/SublimeCodeIntel
### New: 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 ann `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
php artisan ide-helper:meta
app('events')->fire();
\App::make('events')->..
Pre-generated example: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
> Note: This is only available in the `@dev` stability, until a new release is tagged.
> Note: You might need to restart PhpStorm and make sure `.phpstorm.meta.php` is indexed.
> Note: When you receive a FatalException about a class that is not found, check your config (For example, remove S3 as cloud driver when you don't have S3 configured. Remove Redis ServiceProvider when you don't use it.)
### Automatic phpDoc generation for Laravel Facades ### Automatic phpDoc generation for Laravel Facades
Require this package with composer using the following command: Require this package with composer using the following command:
@@ -52,7 +67,6 @@ You can use a in-memory sqlite driver, using the -M option.
You can choose to include helper files. This is not enabled by default, but you can override this with the --helpers (-H) option. You can choose to include helper files. This is not enabled by default, but you can override this with the --helpers (-H) option.
The Illuminate/Support/helpers.php is already set-up, but you can add/remove your own files in the config file. The Illuminate/Support/helpers.php is already set-up, but you can add/remove your own files in the config file.
### Automatic phpDocs for Models ### Automatic phpDocs for Models
> You need to require `doctrine/dbal: ~2.3` in your own composer.json to get database columns. > You need to require `doctrine/dbal: ~2.3` in your own composer.json to get database columns.
+20
View File
@@ -0,0 +1,20 @@
<?= '<?php' ?> namespace PHPSTORM_META {
/**
* PhpStorm Meta file, to provide autocomplete information for PhpStorm
* Generated on <?= date("Y-m-d") ?>.
*
* @author Barry vd. Heuvel <[email protected]>
* @see https://github.com/barryvdh/laravel-ide-helper
* @noinspection PhpUnusedLocalVariableInspection
* @noinspection PhpIllegalArrayKeyTypeInspection
*/
$STATIC_METHOD_TYPES = [
<?php foreach($methods as $method): ?>
<?= $method ?>('') => [
<?php foreach($bindings as $abstract => $class): ?>
'<?= $abstract ?>' instanceof \<?= $class ?>,
<?php endforeach ?> ],
<?php endforeach ?>
];
}
+111
View File
@@ -0,0 +1,111 @@
<?php
/**
* Laravel IDE Helper Generator
*
* @author Barry vd. Heuvel <[email protected]>
* @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 <[email protected]>
*/
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;
protected $methods = [
'\Illuminate\Foundation\Application::make',
'\Illuminate\Contracts\Foundation\Application::make',
'\Illuminate\Contracts\Container\Container::make',
'\Illuminate\Container\Container::make',
'\App::make',
'app',
];
/**
*
* @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('ide-helper::meta', [
'bindings' => $bindings,
'methods' => $this->methods,
])->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),
);
}
}
+9 -2
View File
@@ -11,8 +11,9 @@
namespace Barryvdh\LaravelIdeHelper; namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand; use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
class IdeHelperServiceProvider extends ServiceProvider class IdeHelperServiceProvider extends ServiceProvider
{ {
@@ -60,7 +61,13 @@ class IdeHelperServiceProvider extends ServiceProvider
} }
); );
$this->commands('command.ide-helper.generate', 'command.ide-helper.models'); $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', 'command.ide-helper.meta');
} }
/** /**