REFACTORING: refactor module service providers to reduce amoount of duplicated code
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
<?php namespace Modules\ContactForm\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Providers\ModuleServiceProvider;
|
||||
use Modules\ContactForm\Handlers\ContactForm;
|
||||
use Modules\ContactForm\Widgets\Address\Address;
|
||||
use Modules\ContactForm\Widgets\Form\Form;
|
||||
|
||||
class ContactFormServiceProvider extends ServiceProvider
|
||||
class ContactFormServiceProvider extends ModuleServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*
|
||||
@@ -21,9 +14,7 @@ class ContactFormServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
parent::boot();
|
||||
$this->registerWidgets();
|
||||
}
|
||||
|
||||
@@ -38,54 +29,6 @@ class ContactFormServiceProvider extends ServiceProvider
|
||||
$registrator->register('contactForm', 'contactform::module.name', 'contactform::admin.settings.form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig()
|
||||
{
|
||||
$this->publishes([__DIR__ . '/../Config/config.php' => config_path('contactform.php')]);
|
||||
$this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'contactform');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerViews()
|
||||
{
|
||||
$viewPath = base_path('resources/views/modules/contactform');
|
||||
$sourcePath = __DIR__ . '/../Resources/views';
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], 'module-views');
|
||||
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/contactform';
|
||||
}, \Config::get('view.paths')), [$sourcePath]), 'contactform');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerTranslations()
|
||||
{
|
||||
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'contactform');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array ();
|
||||
}
|
||||
|
||||
private function registerWidgets()
|
||||
{
|
||||
$registrator = $this->app->make('registerWidget');
|
||||
@@ -93,4 +36,14 @@ class ContactFormServiceProvider extends ServiceProvider
|
||||
$registrator->register(Address::class, null, ContactForm::getModuleId());
|
||||
$registrator->register(Form::class, null, ContactForm::getModuleId());
|
||||
}
|
||||
|
||||
protected function setModuleAlias()
|
||||
{
|
||||
$this->alias = 'contactform';
|
||||
}
|
||||
|
||||
protected function setModulePath()
|
||||
{
|
||||
$this->path = __DIR__;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user