-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp_Service_Provider.php
More file actions
77 lines (66 loc) · 1.85 KB
/
Copy pathApp_Service_Provider.php
File metadata and controls
77 lines (66 loc) · 1.85 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
<?php
/**
* App_Service_Provider class file.
*
* @package Mantle
*/
namespace Mantle\Application;
use Mantle\Contracts\Application;
use Mantle\Scheduling\Schedule;
use Mantle\Support\Attributes\Filter;
use Mantle\Support\Service_Provider;
use function Mantle\Support\Helpers\tap;
/**
* App Service Provider
*
* This provider is always loaded by the framework and does not need to be
* declared. It is registered before the providers are booted to allow for the
* application to extend the provider with custom functionality.
*/
class App_Service_Provider extends Service_Provider {
/**
* Constructor.
*
* @param Application $app Application instance.
*/
public function __construct( protected Application $app ) {}
/**
* Register the application service provider
*/
public function register(): void {
$this->app->singleton( 'scheduler', function ( Application $app ): Schedule {
$schedule = new Schedule( $app );
$this->schedule( $schedule );
return $schedule;
} );
}
/**
* Boot the scheduler service.
*/
public function boot(): void {
$this->app->make( 'scheduler' )->schedule_cron_event();
}
/**
* Define the application's command schedule.
*
* Used for legacy command schedule registration. The preferred new way is to
* the use Schedule facade.
*
* @param Schedule $schedule Schedule instance.
*/
protected function schedule( Schedule $schedule ): void {}
/**
* Add a cron schedule for the schedule class.
*
* @param array<string, array{interval: int, display: string}> $schedules
* @return array<string, array{interval: int, display: string}> $schedules
*/
#[Filter( 'cron_schedules' )]
public function add_cron_schedule( array $schedules ): array {
$schedules['mantle_schedule_every_minute'] = [
'interval' => MINUTE_IN_SECONDS,
'display' => 'Every Minute',
];
return $schedules;
}
}