Skip to content
This repository has been archived by the owner on Jul 8, 2018. It is now read-only.

Commit

Permalink
add configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
svenluijten committed Jun 2, 2018
1 parent 1e7ef84 commit 8daabae
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions config/ide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Write to Model Files
|--------------------------------------------------------------------------
|
| Whether or not to write the generated docblocks to your model files.
|
*/
'write_to_model_files' => false,

/*
|--------------------------------------------------------------------------
| Commands
|--------------------------------------------------------------------------
|
| Here you can configure the commands that will be executed.
|
*/
'commands' => [

'generate' => true,

'models' => true,

'meta' => true,

],
];
22 changes: 16 additions & 6 deletions src/Commands/IdeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class IdeCommand extends Command
*/
protected $config;

/**
* @param \Illuminate\Config\Repository $config
*/
public function __construct(Config $config)
{
$this->config = $config;
Expand All @@ -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')) {
Expand Down
14 changes: 9 additions & 5 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 8daabae

Please sign in to comment.