Improve MetaCommand to support injection like ArrayAccess

This commit is contained in:
Thach Nguyen
2018-01-26 22:49:42 +07:00
parent 00604a2431
commit c0f4a497f9
3 changed files with 61 additions and 91 deletions
+18 -47
View File
@@ -15,20 +15,19 @@ use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
/**
* @property \Illuminate\Container\Container $app
*/
class IdeHelperServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
* {@inheritdoc}
*/
protected $defer = true;
/**
* Bootstrap the application events.
*
* @return void
* {@inheritdoc}
*/
public function boot()
{
@@ -36,9 +35,7 @@ class IdeHelperServiceProvider extends ServiceProvider
}
/**
* Register the service provider.
*
* @return void
* {@inheritdoc}
*/
public function register()
{
@@ -49,60 +46,34 @@ class IdeHelperServiceProvider extends ServiceProvider
);
$this->app['command.ide-helper.models'] = $this->app->share(
function () {
return new ModelsCommand();
function ($app) {
return new ModelsCommand($app);
}
);
$this->app['command.ide-helper.meta'] = $this->app->share(
function ($app) {
return new MetaCommand($app['files'], $app['view']);
}
function ($app) {
return new MetaCommand($app);
}
);
$this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
}
/**
* Get the services provided by the provider.
*
* @return array
* {@inheritdoc}
*/
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.
*
* @param string $package
* @param string $namespace
* @param string $path
* @return void
* {@inheritdoc}
*/
public function package($package, $namespace = null, $path = null)
protected function getAppViewPath($package, $namespace = null)
{
// 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');
return $this->app['path'] . "/views/packages/{$package}";
}
}