REFACTORING: refactor module service providers to reduce amoount of duplicated code

This commit is contained in:
Michal Kváček
2016-10-12 17:38:06 +02:00
parent 9b6ae9f9f8
commit d425133cae
8 changed files with 143 additions and 452 deletions
+77
View File
@@ -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);
}
}