use event discovery for modules

This commit is contained in:
Denis Duliçi 2020-07-01 09:35:10 +03:00
parent f4d1fe1877
commit 2b42f3168e
4 changed files with 55 additions and 33 deletions

View File

@ -3,18 +3,28 @@
namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Providers; namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider;
use $MODULE_NAMESPACE$\$STUDLY_NAME$\Listeners\FinishInstallation;
class Event extends Provider class Event extends Provider
{ {
/** /**
* The event listener mappings for the module. * Determine if events and listeners should be automatically discovered.
* *
* @var array * @return bool
*/ */
protected $listen = [ public function shouldDiscoverEvents()
\App\Events\Module\Installed::class => [ {
FinishInstallation::class, return true;
], }
];
/**
* Get the listener directories that should be used to discover events.
*
* @return array
*/
protected function discoverEventsWithin()
{
return [
__DIR__ . '/../Listeners',
];
}
} }

View File

@ -3,26 +3,28 @@
namespace Modules\OfflinePayments\Providers; namespace Modules\OfflinePayments\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider;
use Modules\OfflinePayments\Listeners\FinishInstallation;
use Modules\OfflinePayments\Listeners\ShowAsPaymentMethod;
use Modules\OfflinePayments\Listeners\ShowInSettingsPage;
class Event extends Provider class Event extends Provider
{ {
/** /**
* The event listener mappings for the module. * Determine if events and listeners should be automatically discovered.
* *
* @var array * @return bool
*/ */
protected $listen = [ public function shouldDiscoverEvents()
\App\Events\Module\Installed::class => [ {
FinishInstallation::class, return true;
], }
\App\Events\Module\PaymentMethodShowing::class => [
ShowAsPaymentMethod::class, /**
], * Get the listener directories that should be used to discover events.
\App\Events\Module\SettingShowing::class => [ *
ShowInSettingsPage::class, * @return array
], */
]; protected function discoverEventsWithin()
{
return [
__DIR__ . '/../Listeners',
];
}
} }

View File

@ -44,7 +44,7 @@ class Main extends Provider
*/ */
public function loadTranslations() public function loadTranslations()
{ {
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'offline-payments'); $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'offline-payments');
} }
/** /**

View File

@ -3,18 +3,28 @@
namespace Modules\PaypalStandard\Providers; namespace Modules\PaypalStandard\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as Provider;
use Modules\PaypalStandard\Listeners\ShowAsPaymentMethod;
class Event extends Provider class Event extends Provider
{ {
/** /**
* The event listener mappings for the module. * Determine if events and listeners should be automatically discovered.
* *
* @var array * @return bool
*/ */
protected $listen = [ public function shouldDiscoverEvents()
\App\Events\Module\PaymentMethodShowing::class => [ {
ShowAsPaymentMethod::class, return true;
], }
];
/**
* Get the listener directories that should be used to discover events.
*
* @return array
*/
protected function discoverEventsWithin()
{
return [
__DIR__ . '/../Listeners',
];
}
} }