Repository navigation
Expand file tree
/
Copy pathCommandTask.php
More file actions
103 lines (84 loc) · 2.44 KB
/
Copy pathCommandTask.php
File metadata and controls
103 lines (84 loc) · 2.44 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
102
103
<?php
declare(strict_types=1);
namespace SchedulerBundle\Task;
use SchedulerBundle\Exception\InvalidArgumentException;
use SchedulerBundle\Exception\RuntimeException;
use function is_array;
use function is_string;
/**
* @author Guillaume Loulier <contact@guillaumeloulier.fr>
*/
final class CommandTask extends AbstractTask
{
/**
* @param array<string|int, mixed> $arguments
* @param array<string|int, mixed> $options
*/
public function __construct(
string $name,
string $command,
array $arguments = [],
array $options = []
) {
$this->validateCommand(command: $command);
$this->defineOptions(options: [
'command' => $command,
'arguments' => $arguments,
'options' => $options,
], additionalOptions: [
'command' => 'string',
'arguments' => 'string[]',
'options' => 'string[]',
]);
parent::__construct(name: $name);
}
public function getCommand(): string
{
if (!is_string(value: $this->options['command'])) {
throw new RuntimeException(message: 'The command is not a string');
}
return $this->options['command'];
}
public function setCommand(string $command): self
{
$this->validateCommand(command: $command);
$this->options['command'] = $command;
return $this;
}
/**
* @return array<string|int, mixed>
*/
public function getArguments(): array
{
return is_array(value: $this->options['arguments']) ? $this->options['arguments'] : [];
}
/**
* @param array<string|int, mixed> $arguments
*/
public function setArguments(array $arguments): self
{
$this->options['arguments'] = $arguments;
return $this;
}
/**
* @return array<string|int, mixed>
*/
public function getOptions(): array
{
return is_array(value: $this->options['options']) ? $this->options['options'] : [];
}
/**
* @param array<string|int, mixed> $options
*/
public function setOptions(array $options): self
{
$this->options['options'] = $options;
return $this;
}
private function validateCommand(string $command): void
{
if ('' === $command) {
throw new InvalidArgumentException(message: 'The command argument must be a valid command FQCN|string, empty string given');
}
}
}