|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Bigwhoop\Trumpet\Commands; |
|
4
|
|
|
|
|
5
|
|
|
final class CommandParams |
|
6
|
|
|
{ |
|
7
|
|
|
/** @var string[] */ |
|
8
|
|
|
private $params = []; |
|
9
|
|
|
|
|
10
|
23 |
|
public function __construct(string $params = '', string $argumentSeparator = ' ') |
|
11
|
|
|
{ |
|
12
|
23 |
|
$this->params = str_getcsv($params, $argumentSeparator, '"'); |
|
13
|
23 |
|
} |
|
14
|
|
|
|
|
15
|
23 |
|
public function getFirstArgument(string $default = ''): string |
|
16
|
|
|
{ |
|
17
|
23 |
|
return $this->getArgument(0, $default); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function hasFirstArgument(): bool |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->hasArgument(0); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
20 |
|
public function getSecondArgument(string $default = ''): string |
|
26
|
|
|
{ |
|
27
|
20 |
|
return $this->getArgument(1, $default); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
5 |
|
public function hasSecondArgument(): bool |
|
31
|
|
|
{ |
|
32
|
5 |
|
return $this->hasArgument(1); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
10 |
|
public function getThirdArgument(string $default = ''): string |
|
36
|
|
|
{ |
|
37
|
10 |
|
return $this->getArgument(2, $default); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function hasThirdArgument(): bool |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->hasArgument(2); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
23 |
|
public function getArgument(int $n, string $default = ''): string |
|
46
|
|
|
{ |
|
47
|
23 |
|
$args = $this->getArguments(); |
|
48
|
|
|
|
|
49
|
23 |
|
return array_key_exists($n, $args) ? $args[$n] : $default; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
23 |
|
public function getArguments(): array |
|
53
|
|
|
{ |
|
54
|
23 |
|
return $this->params; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
5 |
|
public function hasArgument(int $n): bool |
|
58
|
|
|
{ |
|
59
|
5 |
|
return array_key_exists($n, $this->getArguments()); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|