StocksNew/Modules/Admin/app/Providers/AdminServiceProvider.php
Sampanna Rimal 53c0140f58 first commit
2024-08-27 17:48:06 +05:45

150 lines
5.5 KiB
PHP

<?php
namespace Modules\Admin\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Admin\Repositories\CountryInterface;
use Modules\Admin\Repositories\CountryRepository;
use Modules\Admin\Repositories\DepartmentInterface;
use Modules\Admin\Repositories\DepartmentRepository;
use Modules\Admin\Repositories\DesignationInterface;
use Modules\Admin\Repositories\DesignationRepository;
use Modules\Admin\Repositories\DistrictInterface;
use Modules\Admin\Repositories\DistrictRepository;
use Modules\Admin\Repositories\DropdownInterface;
use Modules\Admin\Repositories\DropdownRepository;
use Modules\Admin\Repositories\FieldInterface;
use Modules\Admin\Repositories\FieldRepository;
use Modules\Admin\Repositories\MunicipalityInterface;
use Modules\Admin\Repositories\MunicipalityRepository;
use Modules\Admin\Repositories\PromotionDemotionInterface;
use Modules\Admin\Repositories\PromotionDemotionRepository;
use Modules\Admin\Repositories\ProvinceInterface;
use Modules\Admin\Repositories\ProvinceRepository;
use Modules\Admin\Repositories\ResignationInterface;
use Modules\Admin\Repositories\ResignationRepository;
use Modules\Admin\Repositories\TransferInterface;
use Modules\Admin\Repositories\TransferRepository;
use Modules\Admin\Repositories\WarningInterface;
class AdminServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Admin';
protected string $moduleNameLower = 'admin';
/**
* 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'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->bind(FieldInterface::class, FieldRepository::class);
$this->app->bind(DropdownInterface::class, DropdownRepository::class);
$this->app->bind(DepartmentInterface::class, DepartmentRepository::class);
$this->app->bind(DesignationInterface::class, DesignationRepository::class);
$this->app->bind(CountryInterface::class, CountryRepository::class);
$this->app->bind(ProvinceInterface::class, ProvinceRepository::class);
$this->app->bind(DistrictInterface::class, DistrictRepository::class);
$this->app->bind(MunicipalityInterface::class, MunicipalityRepository::class);
$this->app->bind(PromotionDemotionInterface::class, PromotionDemotionRepository::class);
$this->app->bind(TransferInterface::class, TransferRepository::class);
$this->app->bind(ResignationInterface::class, ResignationRepository::class);
$this->app->bind(WarningInterface::class, WarningInterface::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* 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'));
}
}
/**
* 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);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$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);
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
$paths[] = $path . '/modules/' . $this->moduleNameLower;
}
}
return $paths;
}
}