mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-20 02:53:11 +00:00
Improve MetaCommand to support injection like ArrayAccess
This commit is contained in:
+21
-22
@@ -17,21 +17,18 @@ use Symfony\Component\Console\Input\InputOption;
|
|||||||
* A command to generate phpstorm meta data
|
* A command to generate phpstorm meta data
|
||||||
*
|
*
|
||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
|
* @property \Illuminate\Container\Container $laravel
|
||||||
*/
|
*/
|
||||||
class MetaCommand extends Command {
|
class MetaCommand extends Command {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command name.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
*/
|
||||||
protected $name = 'ide-helper:meta';
|
protected $name = 'ide-helper:meta';
|
||||||
protected $filename = '.phpstorm.meta.php';
|
protected $filename = '.phpstorm.meta.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
*/
|
||||||
protected $description = 'Generate metadata for PhpStorm';
|
protected $description = 'Generate metadata for PhpStorm';
|
||||||
|
|
||||||
@@ -42,20 +39,24 @@ class MetaCommand extends Command {
|
|||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
protected $methods = array(
|
protected $methods = array(
|
||||||
'\Illuminate\Foundation\Application::make',
|
'\Illuminate\Foundation\Application::make',
|
||||||
'\Illuminate\Container\Container::make',
|
'new \Illuminate\Foundation\Application',
|
||||||
'\App::make',
|
'\Illuminate\Container\Container::make',
|
||||||
'app',
|
'new \Illuminate\Container\Container',
|
||||||
|
'\App::make',
|
||||||
|
'app',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Filesystem\Filesystem $files
|
* @param \Illuminate\Container\Container $app
|
||||||
* @param \Illuminate\View\Factory $view
|
|
||||||
*/
|
*/
|
||||||
public function __construct($files, $view) {
|
public function __construct($app)
|
||||||
$this->files = $files;
|
{
|
||||||
$this->view = $view;
|
$this->laravel = $app;
|
||||||
|
$this->files = $app['files'];
|
||||||
|
$this->view = $app['view'];
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,14 +74,14 @@ class MetaCommand extends Command {
|
|||||||
if (is_object($concrete)) {
|
if (is_object($concrete)) {
|
||||||
$bindings[$abstract] = get_class($concrete);
|
$bindings[$abstract] = get_class($concrete);
|
||||||
}
|
}
|
||||||
}catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error("Cannot make $abstract: ".$e->getMessage());
|
$this->error("Cannot make $abstract: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $this->view->make('laravel-ide-helper::meta', array(
|
$content = $this->view->make('laravel-ide-helper::meta', array(
|
||||||
'bindings' => $bindings,
|
'bindings' => $bindings,
|
||||||
'methods' => $this->methods,
|
'methods' => $this->methods,
|
||||||
))->render();
|
))->render();
|
||||||
|
|
||||||
$filename = $this->option('filename');
|
$filename = $this->option('filename');
|
||||||
@@ -104,9 +105,7 @@ class MetaCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the console command options.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,20 +15,19 @@ use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
|||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property \Illuminate\Container\Container $app
|
||||||
|
*/
|
||||||
class IdeHelperServiceProvider extends ServiceProvider
|
class IdeHelperServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if loading of the provider is deferred.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
*/
|
||||||
protected $defer = true;
|
protected $defer = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap the application events.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
@@ -36,9 +35,7 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the service provider.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
@@ -49,60 +46,34 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->app['command.ide-helper.models'] = $this->app->share(
|
$this->app['command.ide-helper.models'] = $this->app->share(
|
||||||
function () {
|
function ($app) {
|
||||||
return new ModelsCommand();
|
return new ModelsCommand($app);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->app['command.ide-helper.meta'] = $this->app->share(
|
$this->app['command.ide-helper.meta'] = $this->app->share(
|
||||||
function ($app) {
|
function ($app) {
|
||||||
return new MetaCommand($app['files'], $app['view']);
|
return new MetaCommand($app);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
|
$this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the services provided by the provider.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function provides()
|
public function provides()
|
||||||
{
|
{
|
||||||
return array('command.ide-helper.generate', 'command.ide-helper.models');
|
return array('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the package's component namespaces.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param string $package
|
|
||||||
* @param string $namespace
|
|
||||||
* @param string $path
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function package($package, $namespace = null, $path = null)
|
protected function getAppViewPath($package, $namespace = null)
|
||||||
{
|
{
|
||||||
|
return $this->app['path'] . "/views/packages/{$package}";
|
||||||
// Is it possible to register the config?
|
|
||||||
if (method_exists($this->app['config'], 'package')) {
|
|
||||||
$this->app['config']->package($package, $path.'/config', $namespace);
|
|
||||||
} else {
|
|
||||||
// Load the config for now..
|
|
||||||
$config = $this->app['files']->getRequire($path .'/config/config.php');
|
|
||||||
foreach($config as $key => $value){
|
|
||||||
$this->app['config']->set($namespace.'::'.$key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register view files
|
|
||||||
$appView = $this->app['path']."/views/packages/{$package}";
|
|
||||||
if ($this->app['files']->isDirectory($appView))
|
|
||||||
{
|
|
||||||
$this->app['view']->addNamespace($namespace, $appView);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->app['view']->addNamespace($namespace, $path.'/views');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -1,22 +1,22 @@
|
|||||||
<?= '<?php' ?> namespace PHPSTORM_META {
|
<?= '<?php' ?> 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') ?>.
|
||||||
*
|
*
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @noinspection PhpIllegalArrayKeyTypeInspection */
|
/** @noinspection PhpIllegalArrayKeyTypeInspection,PhpUnusedLocalVariableInspection,PhpUnnecessaryFullyQualifiedNameInspection */
|
||||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
$STATIC_METHOD_TYPES = array(
|
||||||
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
|
<?php foreach ($methods as $method): ?>
|
||||||
$STATIC_METHOD_TYPES = array(
|
<?= strpos($method, 'new ') === 0 ? $method : $method . '(\'\')' ?> => array(
|
||||||
<?php foreach($methods as $method): ?>
|
<?php foreach ($bindings as $abstract => $class): ?>
|
||||||
<?= $method ?>('') => array(
|
'<?= $abstract ?>' instanceof \<?= $class ?>,
|
||||||
<?php foreach($bindings as $abstract => $class): ?>
|
|
||||||
'<?= $abstract ?>' instanceof \<?= $class ?>,
|
|
||||||
<?php endforeach ?> ),
|
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
);
|
),
|
||||||
|
<?php endforeach ?>
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user