Skip to content

Commit

Permalink
Merge pull request #28 from larapack/enhancement/disable-option
Browse files Browse the repository at this point in the history
Add option to disable hooks
  • Loading branch information
marktopper authored Jan 17, 2018
2 parents 7bc3a3b + 7b45a43 commit 8160159
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions publishable/config/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [

'enabled' => env('HOOKS_ENABLED', true),

];
3 changes: 3 additions & 0 deletions src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Filesystem\Filesystem;
use Larapack\Hooks\Composer;
use Larapack\Hooks\Events\Setup;
use Larapack\Hooks\HooksServiceProvider;

class SetupCommand extends Command
{
Expand Down Expand Up @@ -44,6 +45,8 @@ public function handle()

$composer->save();

$this->call('vendor:publish', ['--provider' => HooksServiceProvider::class]);

$this->info('Hooks are now ready to use! Go ahead and try to "php artisan hook:install test-hook"');

event(new Setup());
Expand Down
17 changes: 17 additions & 0 deletions src/HooksServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ class HooksServiceProvider extends ServiceProvider
*/
public function register()
{
$configPath = dirname(__DIR__).'/publishable/config/hooks.php';

$this->mergeConfigFrom($configPath, 'hooks');

if (!config('hooks.enabled', true)) {
return;
}

// Registers resources and commands
if ($this->app->runningInConsole()) {
$this->registerCommands();

$this->publishes(
[$configPath => config_path('hooks.php')],
'hooks-config'
);
}

// Register Hooks system and aliases
Expand Down Expand Up @@ -49,6 +62,10 @@ public function registerHookProviders()
*/
public function boot()
{
if (!config('hooks.enabled', true)) {
return;
}

// Register hook providers
$this->registerHookProviders();
}
Expand Down

0 comments on commit 8160159

Please sign in to comment.