Skip to content

Commit e15d8ef

Browse files
author
Gareth Midwood
authored
Merge pull request #6 from creode/feature/5-add-environment-variables-to-configure-cmd
Feature/5 add environment variables to configure cmd
2 parents c0ce12a + 4c82c6a commit e15d8ef

1 file changed

Lines changed: 84 additions & 2 deletions

File tree

  • src/Environment/Command/Container

src/Environment/Command/Container/Php.php

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ protected function askQuestions()
6363
// usage example will be Drupal sites where clearing cache doesn't do all sites
6464
$this->buildOrImage(
6565
'../vendor/creode/docker/images/php/7.0',
66-
'creode/php-apache:7.0',
66+
'creode/php-apache:7.2',
6767
$this->_config,
6868
[ // builds
69+
'../vendor/creode/docker/images/php/7.0' => 'PHP 7.2',
70+
'../vendor/creode/docker/images/php/7.0' => 'PHP 7.1',
6971
'../vendor/creode/docker/images/php/7.0' => 'PHP 7.0',
7072
'../vendor/creode/docker/images/php/5.6' => 'PHP 5.6',
7173
'../vendor/creode/docker/images/php/5.6-ioncube' => 'PHP 5.6 with ionCube',
@@ -87,13 +89,93 @@ protected function askQuestions()
8789

8890
$this->_config['environment']['VIRTUAL_HOST'] = '.' . $dockername . '.docker';
8991

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

92105
if ($volumeName) {
93106
$this->_config['volumes'] = [$volumeName . ':/var/www/html:nocopy'];
94107
} else {
95108
$this->_config['volumes'] = ['../' . $src . ':/var/www/html'];
96109
}
97-
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();
98180
}
99181
}

0 commit comments

Comments
 (0)