lpj/app/Providers/LpjServiceProvider.php

134 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2024-08-07 03:09:43 +00:00
<?php
2024-08-13 04:54:42 +00:00
namespace Modules\Lpj\Providers;
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
class LpjServiceProvider extends ServiceProvider
2024-08-07 03:09:43 +00:00
{
2024-08-13 04:54:42 +00:00
protected string $moduleName = 'Lpj';
protected string $moduleNameLower = 'lpj';
/**
* Boot the application events.
*/
public function boot()
: void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
if (class_exists('Breadcrumbs')) {
require __DIR__ . '/../../routes/breadcrumbs.php';
}
2024-08-11 06:28:00 +00:00
}
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
/**
* Register commands in the format of Command::class
*/
protected function registerCommands()
: void
{
// $this->commands([]);
}
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
/**
* Register command Schedules.
*/
protected function registerCommandSchedules()
: void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
/**
* Register translations.
*/
public function registerTranslations()
: void
{
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
/**
* Register config.
*/
protected function registerConfig()
: void
{
$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);
2024-08-07 03:09:43 +00:00
}
2024-08-13 04:54:42 +00:00
/**
* Register views.
*/
public function registerViews()
: void
{
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower . '-module-views']);
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
$componentNamespace = str_replace('/', '\\', config('modules.namespace') . '\\' . $this->moduleName . '\\' . ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
/**
* @return array<string>
*/
private function getPublishableViewPaths()
: array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
$paths[] = $path . '/modules/' . $this->moduleNameLower;
}
}
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
return $paths;
}
2024-08-07 03:09:43 +00:00
2024-08-13 04:54:42 +00:00
/**
* Register the service provider.
*/
public function register()
: void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
2024-08-07 03:09:43 +00:00
}
2024-08-13 04:54:42 +00:00
/**
* Get the services provided by the provider.
*
* @return array<string>
*/
public function provides()
: array
{
return [];
}
2024-08-07 03:09:43 +00:00
}