Skip to content

Commit 8160159

Browse files
authored
Merge pull request #28 from larapack/enhancement/disable-option
Add option to disable hooks
2 parents 7bc3a3b + 7b45a43 commit 8160159

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

publishable/config/hooks.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
5+
'enabled' => env('HOOKS_ENABLED', true),
6+
7+
];

src/Commands/SetupCommand.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Filesystem\Filesystem;
77
use Larapack\Hooks\Composer;
88
use Larapack\Hooks\Events\Setup;
9+
use Larapack\Hooks\HooksServiceProvider;
910

1011
class SetupCommand extends Command
1112
{
@@ -44,6 +45,8 @@ public function handle()
4445

4546
$composer->save();
4647

48+
$this->call('vendor:publish', ['--provider' => HooksServiceProvider::class]);
49+
4750
$this->info('Hooks are now ready to use! Go ahead and try to "php artisan hook:install test-hook"');
4851

4952
event(new Setup());

src/HooksServiceProvider.php

+17
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@ class HooksServiceProvider extends ServiceProvider
1212
*/
1313
public function register()
1414
{
15+
$configPath = dirname(__DIR__).'/publishable/config/hooks.php';
16+
17+
$this->mergeConfigFrom($configPath, 'hooks');
18+
19+
if (!config('hooks.enabled', true)) {
20+
return;
21+
}
22+
1523
// Registers resources and commands
1624
if ($this->app->runningInConsole()) {
1725
$this->registerCommands();
26+
27+
$this->publishes(
28+
[$configPath => config_path('hooks.php')],
29+
'hooks-config'
30+
);
1831
}
1932

2033
// Register Hooks system and aliases
@@ -49,6 +62,10 @@ public function registerHookProviders()
4962
*/
5063
public function boot()
5164
{
65+
if (!config('hooks.enabled', true)) {
66+
return;
67+
}
68+
5269
// Register hook providers
5370
$this->registerHookProviders();
5471
}

0 commit comments

Comments
 (0)