Skip to content

Commit 4c82c6a

Browse files
author
Gareth Midwood
committed
Add environment variable management
1 parent d62757b commit 4c82c6a

1 file changed

Lines changed: 81 additions & 1 deletion

File tree

  • src/Environment/Command/Container

src/Environment/Command/Container/Php.php

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,93 @@ protected function askQuestions()
8989

9090
$this->_config['environment']['VIRTUAL_HOST'] = '.' . $dockername . '.docker';
9191

92+
$editEnvironmentVariables = false;
93+
94+
$this->askYesNoQuestion(
95+
'Edit environment variables',
96+
$editEnvironmentVariables
97+
);
98+
99+
if ($editEnvironmentVariables) {
100+
$this->_editEnvironmentVariables();
101+
}
102+
92103
$this->_config['links'] = [];
93104

94105
if ($volumeName) {
95106
$this->_config['volumes'] = [$volumeName . ':/var/www/html:nocopy'];
96107
} else {
97108
$this->_config['volumes'] = ['../' . $src . ':/var/www/html'];
98109
}
99-
110+
}
111+
112+
private function _editEnvironmentVariables()
113+
{
114+
if (isset($this->_config['environment']) && count($this->_config['environment']) > 1) {
115+
$this->_removeEnvironmentVariables();
116+
}
117+
118+
$this->_addEnvironmentVariables();
119+
}
120+
121+
private function _removeEnvironmentVariables()
122+
{
123+
$removeEnvironmentVariables = false;
124+
125+
$this->askYesNoQuestion(
126+
'Remove environment variables',
127+
$removeEnvironmentVariables
128+
);
129+
130+
if (!$removeEnvironmentVariables) {
131+
return;
132+
}
133+
134+
foreach($this->_config['environment'] as $varName => $value) {
135+
// don't let them remove the virtual host name
136+
if ($varName == 'VIRTUAL_HOST') {
137+
continue;
138+
}
139+
140+
$removeEnvVar = false;
141+
142+
$this->askYesNoQuestion(
143+
'Remove ' . $varName,
144+
$removeEnvVar
145+
);
146+
147+
if ($removeEnvVar) {
148+
unset($this->_config['environment'][$varName]);
149+
}
150+
}
151+
}
152+
153+
private function _addEnvironmentVariables()
154+
{
155+
$addNewEnvironmentVariable = false;
156+
157+
$this->askYesNoQuestion(
158+
'Add new environment variable',
159+
$addNewEnvironmentVariable
160+
);
161+
162+
if (!$addNewEnvironmentVariable) {
163+
return;
164+
}
165+
166+
$this->askQuestion(
167+
'Environment Variable Name',
168+
$varName
169+
);
170+
171+
$this->askQuestion(
172+
'Environment Variable Value',
173+
$value
174+
);
175+
176+
$this->_config['environment'][$varName] = $value;
177+
178+
// offer to add another
179+
$this->_addEnvironmentVariables();
100180
}
101181
}

0 commit comments

Comments
 (0)