Skip to content

Commit

Permalink
Merge pull request #20 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 db2f5db + 47dc725 commit 3844566
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions publishable/config/voyager-hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [

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

'add-route' => true,
'add-hook-menu-item' => true,
'add-hook-permissions' => true,
'publish-vendor-files' => true,

];
38 changes: 38 additions & 0 deletions src/VoyagerHooksServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Larapack\VoyagerHooks;

use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\ServiceProvider;
use Larapack\Hooks\Events\Setup;
use Larapack\Hooks\HooksServiceProvider;
Expand All @@ -17,9 +18,24 @@ class VoyagerHooksServiceProvider extends ServiceProvider
*/
public function register()
{
$configPath = dirname(__DIR__).'/publishable/config/voyager-hooks.php';

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

// Register the HooksServiceProvider
$this->app->register(HooksServiceProvider::class);

if (!$this->enabled()) {
return;
}

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

// Load views
$this->loadViewsFrom(__DIR__.'/../resources/views', 'voyager-hooks');
}
Expand All @@ -31,6 +47,10 @@ public function register()
*/
public function boot(Dispatcher $events)
{
if (!$this->enabled()) {
return;
}

if (config('voyager-hooks.add-route', true)) {
$events->listen('voyager.admin.routing', [$this, 'addHookRoute']);
}
Expand All @@ -42,6 +62,10 @@ public function boot(Dispatcher $events)
if (config('voyager-hooks.add-hook-permissions', true)) {
$events->listen(Setup::class, [$this, 'addHookPermissions']);
}

if (config('voyager-hooks.publish-vendor-files', true)) {
$events->listen(Setup::class, [$this, 'publishVendorFiles']);
}
}

public function addHookRoute($router)
Expand Down Expand Up @@ -99,4 +123,18 @@ public function addHookPermissions()
'table_name' => null,
]);
}

public function publishVendorFiles()
{
Artisan::call('vendor:publish', ['--provider' => static::class]);
}

public function enabled()
{
if (config('voyager-hooks.enabled', true)) {
return config('hooks.enabled', true);
}

return config('voyager-hooks.enabled', true);
}
}

0 comments on commit 3844566

Please sign in to comment.