-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand_Event.php
More file actions
74 lines (62 loc) · 1.68 KB
/
Copy pathCommand_Event.php
File metadata and controls
74 lines (62 loc) · 1.68 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
<?php
/**
* Command_Event class file.
*
* @package Mantle
*/
namespace Mantle\Scheduling;
use DateTimeZone;
use Mantle\Contracts\Application;
use Mantle\Contracts\Exceptions\Handler;
use Throwable;
/**
* Command Event
*
* Allow a command to be run on a specific schedule.
*/
class Command_Event extends Event {
/**
* The associated command arguments (flags).
*
* @var array<string, string>
*/
public $assoc_args;
/**
* Constructor.
*
* @param string $command Command class to run.
* @param array<mixed> $parameters Arguments for the command.
* @param array<string, string> $assoc_args Associated arguments for the command.
* @param DateTimeZone|null $timezone Timezone for the event.
*/
public function __construct( string $command, array $parameters = [], array $assoc_args = [], ?DateTimeZone $timezone = null ) {
parent::__construct( $command, $parameters, $timezone );
$this->assoc_args = $assoc_args;
}
/**
* Run the event.
*
* @param Application $container Container instance.
*/
#[\Override]
public function run( Application $container ): void {
if ( ! $this->filters_pass( $container ) ) {
return;
}
$this->call_before_callbacks( $container );
try {
if ( is_callable( $this->callback ) ) {
call_user_func( $this->callback, $this->parameters, $this->assoc_args );
} else {
$instance = $container->make( $this->callback );
$instance->handle( $this->parameters, $this->assoc_args );
}
$this->exit_code = 0;
} catch ( Throwable $e ) {
$container->make( Handler::class )->report( $e );
$this->exception = $e;
$this->exit_code = 1;
}
$this->call_after_callbacks( $container );
}
}