From 8daabaef4c2d5c8730a2bc055b188de36da22913 Mon Sep 17 00:00:00 2001 From: Sven Luijten Date: Sat, 2 Jun 2018 21:54:36 +0200 Subject: [PATCH] add configuration --- README.md | 19 +++++++++++++++++++ config/ide.php | 31 +++++++++++++++++++++++++++++++ src/Commands/IdeCommand.php | 22 ++++++++++++++++------ src/ServiceProvider.php | 14 +++++++++----- 4 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 config/ide.php diff --git a/README.md b/README.md index 75c1004..451b6d8 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ that same command in all my projects. And thus, this package was born. - [Downloading](#downloading) - [Registering the service provider](#registering-the-service-provider) - [Usage](#usage) +- [Configuration](#configuration) - [Contributing](#contributing) - [License](#license) @@ -55,6 +56,24 @@ To (re-)generate IDE helper files, execute the following command: $ php artisan ide ``` +## Configuration +To publish the configuration file for this package, run the following command: + +```bash +$ php artisan vendor:publish --provider="Sven\LaravelIde\ServiceProvider" +``` + +This will create a new file at `config/ide.php`, where you can configure the following +values: + +### `write_to_model_files` +This option is to determine whether or not to write the generated docblocks for models +directly to the model files or to create a seperate file for them. + +### `commands.*` +The keys here stand for the `ide-helper` command to execute. If you wish to disable one +of them, set the value to `false`. + ## Contributing All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the [CONTRIBUTING.md](CONTRIBUTING.md) first, diff --git a/config/ide.php b/config/ide.php new file mode 100644 index 0000000..58ebced --- /dev/null +++ b/config/ide.php @@ -0,0 +1,31 @@ + false, + + /* + |-------------------------------------------------------------------------- + | Commands + |-------------------------------------------------------------------------- + | + | Here you can configure the commands that will be executed. + | + */ + 'commands' => [ + + 'generate' => true, + + 'models' => true, + + 'meta' => true, + + ], +]; diff --git a/src/Commands/IdeCommand.php b/src/Commands/IdeCommand.php index 3ad5c99..b28a50f 100644 --- a/src/Commands/IdeCommand.php +++ b/src/Commands/IdeCommand.php @@ -22,9 +22,6 @@ class IdeCommand extends Command */ protected $config; - /** - * @param \Illuminate\Config\Repository $config - */ public function __construct(Config $config) { $this->config = $config; @@ -34,13 +31,26 @@ public function __construct(Config $config) public function handle(): void { - $this->callSilent('ide-helper:generate'); - $this->callSilent('ide-helper:models', $this->getWriteConfiguration()); - $this->callSilent('ide-helper:meta'); + if (!\in_array(true, $this->config->get('ide.commands'), true)) { + $this->error('None of the commands to run are enabled in the config.'); + + exit(1); + } + + $this->callIf('ide.commands.generate', 'ide-helper:generate'); + $this->callIf('ide.commands.models', 'ide-helper:models', $this->getWriteConfiguration()); + $this->callIf('ide.commands.meta', 'ide-helper:meta'); $this->info('Successfully generated PhpStorm meta files!'); } + protected function callIf($config, $command, array $parameters = []): void + { + if ($this->config->get($config)) { + $this->callSilent($command, $parameters); + } + } + protected function getWriteConfiguration(): array { if ($this->config->get('ide.write_to_model_files')) { diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 2ae619f..70ebbe7 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -7,13 +7,17 @@ class ServiceProvider extends LaravelProvider { - /** - * Register the application services. - * - * @return void - */ public function register() { + $this->mergeConfigFrom(__DIR__.'/../config/ide.php', 'ide'); + $this->commands(IdeCommand::class); } + + public function boot() + { + $this->publishes([ + __DIR__.'/../config/ide.php' => config_path('ide.php'), + ], 'config'); + } }