Repository navigation
Expand file tree
/
Copy pathCustomModuleProvider.php
More file actions
101 lines (89 loc) · 2.83 KB
/
Copy pathCustomModuleProvider.php
File metadata and controls
101 lines (89 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace Modules\Addons\CustomModule;
use App\Models\Device;
use App\Providers\ModuleServiceProvider;
use Illuminate\Console\Scheduling\Schedule;
use Modules\Addons\CustomModule\Commands\CustomModuleCommand;
use Modules\Addons\CustomModule\Commands\IpmiBmcResetCommand;
use Modules\Addons\CustomModule\Observers\DeviceObserver;
/**
* Class CustomModuleProvider
*
* Keep the provider small: it should only bootstrap services owned by the module.
* Event listeners live in CustomModuleEventHandler and model hooks live in observers.
* This follows the same pattern as other EasyDCIM addons, where ModuleRepository
* automatically subscribes a {ModuleName}EventHandler class when it exists.
*
* @package Modules\Addons\CustomModule
*/
class CustomModuleProvider extends ModuleServiceProvider
{
/**
* Register scheduled tasks for this module.
*
* @return void
*/
public function boot(Schedule $schedule)
{
parent::boot($schedule);
$this->registerSchedule($schedule);
$this->registerModelObservers();
}
/**
* Register module services.
*
* @return void
*/
public function register()
{
$this->app->register(BackendUiNavigationServiceProvider::class);
$this->app['translator']->addNamespace(
'custom-module',
base_path('modules/addons/CustomModule/lang')
);
$this->registerCommands();
// Example only: put real module table changes in database/migrations.
// For small demo/seed logic see Support\Installers\CustomModelTableInstaller.
// app(\Modules\Addons\CustomModule\Support\Installers\CustomModelTableInstaller::class)->install();
parent::register('CustomModule');
}
/**
* Register Artisan commands provided by this module.
*
* @return void
*/
private function registerCommands(): void
{
$this->commands([
CustomModuleCommand::class,
IpmiBmcResetCommand::class,
]);
}
/**
* Register scheduled commands.
*
* @return void
*/
private function registerSchedule(Schedule $schedule): void
{
// Example: run the IPMI BMC-reset command every day at midnight.
// Remove or adjust the schedule to match your needs.
$schedule->command('custom-module:ipmi-bmc-reset')
->daily()
->withoutOverlapping()
->onOneServer();
// Example: run the generic sample command every hour.
// $schedule->command('custom-module:command')->hourly();
}
/**
* Register Eloquent observers.
*
* Observers are preferred over large inline model callbacks in the provider.
*
* @return void
*/
private function registerModelObservers(): void
{
Device::observe(DeviceObserver::class);
}
}