This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandConfiguration.php
181 lines (164 loc) · 4 KB
/
CommandConfiguration.php
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
*/
namespace Ulrack\Command\Dao;
use Ulrack\Command\Common\Dao\CommandConfigurationInterface;
class CommandConfiguration implements CommandConfigurationInterface
{
/**
* Contains the service configuration for the current command.
*
* @var string
*/
private $service;
/**
* Retrieves the description of the command.
*
* @var string
*/
private $description;
/**
* Contains all registered nested commands.
*
* @var CommandConfigurationInterface[]
*/
private $commands = [];
/**
* Contains the parameters for the current configuration.
*
* @var array
*/
private $parameters;
/**
* Contains the flags for the current configuration.
*
* @var array
*/
private $flags;
/**
* Constructor.
*
* @param string $service
* @param string $description
* @param array $parameters
* @param array $flags
*/
public function __construct(
string $service = '',
string $description = '',
array $parameters = [],
array $flags = []
) {
$this->service = $service;
$this->description = $description;
$this->parameters = $parameters;
$this->flags = array_merge(
$flags,
[
[
'long' => 'help',
'short' => 'h',
'description' => 'Explains the command.'
],
[
'long' => 'no-interaction',
'short' => 'ni',
'description' => 'Prevents interaction during the execution of a command.'
],
[
'long' => 'verbose',
'short' => 'v',
'description' => 'Displays verbose output for a command.'
],
[
'long' => 'quiet',
'short' => 'q',
'description' => 'Silences all output.'
]
]
);
}
/**
* Adds a nested command configuration to the configuration.
*
* @param string $command
* @param CommandConfigurationInterface $configuration
*
* @return void
*/
public function addCommandConfiguration(
string $command,
CommandConfigurationInterface $configuration
): void {
$this->commands[$command] = $configuration;
}
/**
* Retrieves the allowed flags for the command.
*
* @return array
*/
public function getFlags(): array
{
return $this->flags;
}
/**
* Retrieves the allowed parameters.
*
* @return array
*/
public function getParameters(): array
{
return $this->parameters;
}
/**
* Retrieves a command configuration nested inside the configuration.
*
* @param string $command
*
* @return CommandConfigurationInterface
*/
public function getCommand(string $command): CommandConfigurationInterface
{
return $this->commands[$command];
}
/**
* Retrieves a command configuration nested inside the configuration.
*
* @param string $command
*
* @return bool
*/
public function hasCommand(string $command): bool
{
return isset($this->commands[$command]);
}
/**
* Retrieves the service key.
*
* @return string
*/
public function getService(): string
{
return $this->service;
}
/**
* Retrieves all nested commands.
*
* @return string[]
*/
public function getCommands(): array
{
return array_keys($this->commands);
}
/**
* Retrieves the description for the command configuration.
*
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
}