Usermanager/Providers/UsermanagerServiceProvider.php

117 lines
3.2 KiB
PHP
Raw Normal View History

2023-05-16 04:51:54 +00:00
<?php
2023-05-21 05:37:35 +00:00
namespace Modules\Usermanager\Providers;
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
use Config;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\ServiceProvider;
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
class UsermanagerServiceProvider extends ServiceProvider
{
/**
* @var string $moduleName
*/
protected $moduleName = 'Usermanager';
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
/**
* @var string $moduleNameLower
*/
protected $moduleNameLower = 'usermanager';
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations'));
}
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang'));
}
}
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'),
], 'config');
$this->mergeConfigFrom(
module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower
);
}
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
/**
* Register views.
*
* @return void
*/
public function registerViews()
{
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
$sourcePath = module_path($this->moduleName, 'Resources/views');
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
$this->publishes([
$sourcePath => $viewPath
], ['views', $this->moduleNameLower . '-module-views']);
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
}
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
private function getPublishableViewPaths()
: array
{
$paths = [];
foreach (Config::get('view.paths') as $path) {
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
$paths[] = $path . '/modules/' . $this->moduleNameLower;
}
}
return $paths;
2023-05-16 04:51:54 +00:00
}
2023-05-21 05:37:35 +00:00
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->register(RouteServiceProvider::class);
}
2023-05-16 04:51:54 +00:00
2023-05-21 05:37:35 +00:00
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [];
2023-05-16 04:51:54 +00:00
}
}