Files
webstatement/app/Providers/WebstatementServiceProvider.php
Daeng Deni Mardaeni 4a3c7085ce feat(webstatement): tambahkan command dan scheduler untuk generate biaya kartu ATM
- Menambahkan `GenerateBiayakartuCommand` untuk memproses biaya kartu ATM.
- Mendaftarkan command baru di `WebstatementServiceProvider`.
- Menjadwalkan command `webstatement:generate-biaya-kartu` pada tanggal 14 setiap bulan pukul 18:00.
- Menambahkan log output untuk scheduler ke file `biaya-kartu-scheduler.log`.

Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
2025-05-09 08:53:52 +07:00

128 lines
3.6 KiB
PHP

<?php
namespace Modules\Webstatement\Providers;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Webstatement\Console\GenerateBiayakartuCommand;
use Nwidart\Modules\Traits\PathNamespace;
class WebstatementServiceProvider extends ServiceProvider
{
use PathNamespace;
protected string $name = 'Webstatement';
protected string $nameLower = 'webstatement';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
if (class_exists('Breadcrumbs')) {
require __DIR__ . '/../../routes/breadcrumbs.php';
}
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
$this->commands([
GenerateBiayakartuCommand::class
]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
$schedule = $this->app->make(Schedule::class);
$schedule->command('webstatement:generate-biaya-kartu')
->monthlyOn(14, '18:00')
->appendOutputTo(storage_path('logs/biaya-kartu-scheduler.log'));
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->nameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->nameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->nameLower);
$sourcePath = module_path($this->name, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
$componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path')));
Blade::componentNamespace($componentNamespace, $this->nameLower);
}
/**
* 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->nameLower)) {
$paths[] = $path.'/modules/'.$this->nameLower;
}
}
return $paths;
}
}