Cetaklabel/Providers/CetakLabelServiceProvider.php

131 lines
3.7 KiB
PHP
Raw Normal View History

2023-05-15 10:03:46 +00:00
<?php
2023-05-15 14:14:52 +00:00
namespace Modules\CetakLabel\Providers;
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
use Config;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\ServiceProvider;
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
class CetakLabelServiceProvider extends ServiceProvider
2023-05-15 10:03:46 +00:00
{
2023-05-15 14:14:52 +00:00
/**
* @var string $moduleName
*/
protected $moduleName = 'CetakLabel';
/**
* @var string $moduleNameLower
*/
protected $moduleNameLower = 'cetaklabel';
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->registerDatabase();
$this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations'));
}
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
$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, 'Resources/lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang'));
}
}
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +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-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
/**
* Register views.
*
* @return void
*/
public function registerViews()
{
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
$sourcePath = module_path($this->moduleName, 'Resources/views');
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
$this->publishes([
$sourcePath => $viewPath
], ['views', $this->moduleNameLower . '-module-views']);
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
}
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +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-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
protected function registerDatabase()
{
$this->publishes([
module_path($this->moduleName, 'Config/database.php') => config_path($this->moduleNameLower . '.php'),
], 'database');
array_merge(
require base_path() . '/config/database.php',
require base_path() . '/Modules/CetakLabel/Config/database.php'
);
2023-05-15 10:03:46 +00:00
}
2023-05-15 14:14:52 +00:00
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->register(RouteServiceProvider::class);
}
2023-05-15 10:03:46 +00:00
2023-05-15 14:14:52 +00:00
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [];
2023-05-15 10:03:46 +00:00
}
}