|
7 | 7 | use Platformsh\Client\Model\ProjectLevelVariable; |
8 | 8 | use Platformsh\Client\Model\Resource as ApiResource; |
9 | 9 | use Platformsh\Client\Model\Variable as EnvironmentLevelVariable; |
| 10 | +use Platformsh\ConsoleForm\Field\ArrayField; |
10 | 11 | use Platformsh\ConsoleForm\Field\BooleanField; |
11 | 12 | use Platformsh\ConsoleForm\Field\Field; |
12 | 13 | use Platformsh\ConsoleForm\Field\OptionsField; |
@@ -182,6 +183,33 @@ protected function getFields() |
182 | 183 | return null; |
183 | 184 | }, |
184 | 185 | ]); |
| 186 | + $fields['application_scope'] = new ArrayField('Application scope', [ |
| 187 | + 'optionName' => 'app-scope', |
| 188 | + 'description' => 'A list of application names to which this variable will apply.', |
| 189 | + 'questionLine' => 'To which applications should this variable apply?', |
| 190 | + 'default' => [], |
| 191 | + 'required' => false, |
| 192 | + //q'avoidQuestion' => true, |
| 193 | + 'validator' => function ($values) { |
| 194 | + if ($this->hasSelectedEnvironment()) { |
| 195 | + $deployment = $this->api()->getCurrentDeployment($this->getSelectedEnvironment(), false, false); |
| 196 | + if (!$deployment) { |
| 197 | + return false; |
| 198 | + } |
| 199 | + $appNames = array_keys($deployment->webapps); |
| 200 | + foreach ($values as $value) { |
| 201 | + if (!in_array($value, $appNames, true)) { |
| 202 | + throw new InvalidArgumentException(sprintf( |
| 203 | + 'The app "%s" was not found. Valid app names are: %s', |
| 204 | + $value, |
| 205 | + implode(', ', $appNames) |
| 206 | + )); |
| 207 | + } |
| 208 | + } |
| 209 | + } |
| 210 | + return true; |
| 211 | + }, |
| 212 | + ]); |
185 | 213 | $fields['name'] = new Field('Name', [ |
186 | 214 | 'description' => 'The variable name', |
187 | 215 | 'validators' => [ |
|
0 commit comments