diff --git a/src/Handler.php b/src/Handler.php index dcb870ba150fa973dd5582c64f48bb5dae27ff69..7e1cb6a0ce7594dd51779373b4a0adb1d1bfb11e 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -16,6 +16,11 @@ use Symfony\Component\Yaml\Yaml; */ class Handler extends BaseHandler { + /** + * @var array + */ + protected $options; + /** * Configure Drupal Project for Docker. * @@ -189,93 +194,104 @@ class Handler extends BaseHandler { /** * Retrieve options from composer.json "extra" configuration. * + * @param null $key + * Optional name of an option to be received instead of the full set of options. + * * @return array * The options. */ - protected function getOptions() { - $projectname = str_replace([' ', '-', '_', '.'], '', basename(getcwd())); - $env = new Dotenv('docker4drupal', $this->io); - $env->put('COMPOSE_PROJECT_NAME', $projectname); - $extra = $this->composer->getPackage()->getExtra() + ['docker4drupal' => []]; - $options = NestedArray::mergeDeep([ - 'projectname' => $projectname, - 'docker0' => [ - 'ip' => $this->getLocalIpv4('docker0'), - ], - 'live' => [ - 'root' => '', - 'uri' => '', - 'host' => '', - 'user' => $env->receive('live_host_username', 'Remote username for host of the live site', getenv('USER')), - ], - 'drush' => [ - 'sql' => [ - 'tables' => [ - 'structure' => [ - 'cache', - 'cache_*', - 'history', - 'search_*', - 'sessions', - 'watchdog', - ], - 'skip' => [ - 'migration_*', + public function getOptions($key = NULL) { + if ($this->options === NULL) { + $env = new Dotenv('docker4drupal', $this->io); + $projectname = getenv('COMPOSE_PROJECT_NAME'); + if (empty($projectname)) {$projectname = str_replace([' ', '-', '_', '.'], '', basename(getcwd())); + $env->put('COMPOSE_PROJECT_NAME', $projectname); + } + $extra = $this->composer->getPackage()->getExtra() + ['docker4drupal' => []]; + $options = NestedArray::mergeDeep([ + 'projectname' => $projectname, + 'docker0' => [ + 'ip' => $this->getLocalIpv4('docker0'), + ], + 'live' => [ + 'root' => '', + 'uri' => '', + 'host' => '', + 'user' => $env->receive('live_host_username', 'Remote username for host of the live site', getenv('USER')), + ], + 'drush' => [ + 'sql' => [ + 'tables' => [ + 'structure' => [ + 'cache', + 'cache_*', + 'history', + 'search_*', + 'sessions', + 'watchdog', + ], + 'skip' => [ + 'migration_*', + ], ], ], ], - ], - 'drupal' => [ - 'version' => '8', - ], - 'php' => [ - 'version' => '7.0', - 'xdebug' => 1, - ], - 'webserver' => [ - 'type' => 'apache', - ], - 'varnish' => [ - 'enable' => 0, - ], - 'redis' => [ - 'version' => '4.0', - ], - 'dbbrowser' => [ - 'type' => 'pma', - ], - 'solr' => [ - 'enable' => 0, - 'version' => '6.6', - ], - 'node' => [ - 'enable' => 0, - 'key' => '', - 'path' => '', - ], - 'memcached' => [ - 'enable' => 0, - ], - 'rsyslog' => [ - 'enable' => 0, - ], - 'athenapdf' => [ - 'enable' => 0, - 'key' => '', - ], - 'blackfire' => [ - 'enable' => 0, - 'id' => '', - 'token' => '', - ], - 'webgrind' => [ - 'enable' => 0, - ], - 'wkhtmltox' => [ - 'enable' => 0, - ], - ], $extra['docker4drupal']); - return $env->replaceEnvironmentVariables($options); + 'drupal' => [ + 'version' => '8', + ], + 'php' => [ + 'version' => '7.0', + 'xdebug' => 1, + ], + 'webserver' => [ + 'type' => 'apache', + ], + 'varnish' => [ + 'enable' => 0, + ], + 'redis' => [ + 'version' => '4.0', + ], + 'dbbrowser' => [ + 'type' => 'pma', + ], + 'solr' => [ + 'enable' => 0, + 'version' => '6.6', + ], + 'node' => [ + 'enable' => 0, + 'key' => '', + 'path' => '', + ], + 'memcached' => [ + 'enable' => 0, + ], + 'rsyslog' => [ + 'enable' => 0, + ], + 'athenapdf' => [ + 'enable' => 0, + 'key' => '', + ], + 'blackfire' => [ + 'enable' => 0, + 'id' => '', + 'token' => '', + ], + 'webgrind' => [ + 'enable' => 0, + ], + 'wkhtmltox' => [ + 'enable' => 0, + ], + ], $extra['docker4drupal']); + $this->options = $env->replaceEnvironmentVariables($options); + } + if ($key !== NULL) { + return $this->options[$key]; + } + return $this->options; } /**