Skip to content

Commit

Permalink
added event and listener stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Apr 3, 2020
1 parent 04f2872 commit 026b649
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/Console/Stubs/Modules/json.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"category": "accounting",
"active": 1,
"providers": [
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\Event",
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\Main"
],
"aliases": {},
Expand Down
36 changes: 36 additions & 0 deletions app/Console/Stubs/Modules/listeners/install.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners;

use App\Events\Module\Installed as Event;
use App\Traits\Permissions;

class InstallModule
{
use Permissions;

public $alias = '$ALIAS$';

/**
* Handle the event.
*
* @param Event $event
* @return void
*/
public function handle(Event $event)
{
if ($event->alias != $this->alias) {
return;
}

$this->updatePermissions();
}

protected function updatePermissions()
{
// c=create, r=read, u=update, d=delete
$this->attachPermissionsToAdminRoles([
$this->alias . '-main' => 'c,r,u,d',
]);
}
}
20 changes: 20 additions & 0 deletions app/Console/Stubs/Modules/providers/event.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider;
use $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners\InstallModule;

class Event extends Provider
{
/**
* The event listener mappings for the module.
*
* @var array
*/
protected $listen = [
\App\Events\Module\Installed::class => [
InstallModule::class,
],
];
}
2 changes: 1 addition & 1 deletion app/Console/Stubs/Modules/routes/admin.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Route;

Route::group([
'middleware' => 'admin',
'namespace' => 'Modules\$STUDLY_NAME$\Http\Controllers'
'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'
], function () {
Route::prefix('$ALIAS$')->group(function() {
// Route::get('/', 'Main@index');
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Stubs/Modules/routes/portal.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Route;
Route::group([
'prefix' => 'portal',
'middleware' => 'portal',
'namespace' => 'Modules\$STUDLY_NAME$\Http\Controllers'
'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'
], function () {
// Route::get('invoices/{invoice}/$ALIAS$', 'Main@show')->name('portal.invoices.$ALIAS$.show');
// Route::post('invoices/{invoice}/$ALIAS$/confirm', 'Main@confirm')->name('portal.invoices.$ALIAS$.confirm');
Expand Down
8 changes: 6 additions & 2 deletions config/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
'enabled' => true,
'path' => base_path() . '/app/Console/Stubs/Modules',
'files' => [
'listeners/install' => 'Listeners/InstallModule.php',
'providers/event' => 'Providers/Event.php',
'routes/admin' => 'Routes/admin.php',
'routes/portal' => 'Routes/portal.php',
'lang/general' => 'Resources/lang/en-GB/general.php',
Expand All @@ -35,8 +37,10 @@
'package' => 'package.json',
],
'replacements' => [
'routes/admin' => ['ALIAS', 'STUDLY_NAME'],
'routes/portal' => ['ALIAS', 'STUDLY_NAME'],
'listeners/install' => ['ALIAS', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'providers/event' => ['ALIAS', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'routes/admin' => ['ALIAS', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'routes/portal' => ['ALIAS', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'webpack' => ['ALIAS'],
'json' => ['ALIAS', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'lang/general' => ['ALIAS', 'STUDLY_NAME'],
Expand Down
4 changes: 2 additions & 2 deletions modules/OfflinePayments/Providers/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Modules\OfflinePayments\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider;
use Modules\OfflinePayments\Listeners\InstallModule;
use Modules\OfflinePayments\Listeners\ShowPaymentMethod;
use Modules\OfflinePayments\Listeners\ShowSetting;

class Event extends ServiceProvider
class Event extends Provider
{
/**
* The event listener mappings for the module.
Expand Down

0 comments on commit 026b649

Please sign in to comment.