Files
core/app/CMS/Modules/ServiceProviders/ServiceProvider.php
T

75 lines
1.8 KiB
PHP

<?php
namespace App\CMS\Modules\ServiceProviders;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
abstract class ServiceProvider extends LaravelServiceProvider
{
/**
* 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->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/' . $this->alias;
}, \Config::get('view.paths')), [$sourcePath]), $this->alias);
if (is_dir($sourcePath)) {
$this->publishes([$sourcePath => $viewPath], 'module-views');
}
}
/**
* Register translations.
* @return void
*/
protected function registerTranslations()
{
$this->loadTranslationsFrom($this->path . '/../Resources/lang', $this->alias);
}
}