REFACTORING: refactor module service providers to reduce amoount of duplicated code
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
abstract class ModuleServiceProvider extends ServiceProvider {
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
protected $alias = false;
|
||||
protected $path = false;
|
||||
|
||||
abstract protected function setModuleAlias();
|
||||
abstract protected function setModulePath();
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->setModuleAlias();
|
||||
$this->setModulePath();
|
||||
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig()
|
||||
{
|
||||
$this->publishes([$this->path . '/../Config/config.php' => config_path($this->alias.'.php')]);
|
||||
$this->mergeConfigFrom($this->path . '/../Config/config.php', $this->alias);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerViews()
|
||||
{
|
||||
$viewPath = base_path('resources/views/modules/'.$this->alias);
|
||||
$sourcePath = $this->path . '/../Resources/views';
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], 'module-views');
|
||||
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/'.$this->alias;
|
||||
}, \Config::get('view.paths')), [$sourcePath]), $this->alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerTranslations()
|
||||
{
|
||||
$this->loadTranslationsFrom($this->path . '/../Resources/lang', $this->alias);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user