Skip to content

Commit

Permalink
Add default values for manager version option
Browse files Browse the repository at this point in the history
Issue #24
  • Loading branch information
francoispluchino committed Apr 10, 2019
1 parent bfaa163 commit 847ebd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
28 changes: 16 additions & 12 deletions Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ public function get($key, $default = null)
{
if (\array_key_exists($key, $this->cacheEnv)) {
return $this->cacheEnv[$key];
} else {
$envKey = $this->convertEnvKey($key);
$envValue = getenv($envKey);
}

$envKey = $this->convertEnvKey($key);
$envValue = getenv($envKey);

if (false !== $envValue) {
return $this->cacheEnv[$key] = $this->convertEnvValue($envValue, $envKey);
}
if (false !== $envValue) {
return $this->cacheEnv[$key] = $this->convertEnvValue($envValue, $envKey);
}

$defaultValue = $this->getDefaultValue($key, $default);

return \array_key_exists($key, $this->config)
? $this->getByManager($key, $this->config[$key], $default)
: $this->getDefaultValue($key, $default);
? $this->getByManager($key, $this->config[$key], $defaultValue)
: $defaultValue;
}

/**
Expand Down Expand Up @@ -214,9 +216,11 @@ private function convertJson($value, $environmentVariable)
*/
private function getDefaultValue($key, $default = null)
{
return null === $default && \array_key_exists($key, $this->defaults)
$value = null === $default && \array_key_exists($key, $this->defaults)
? $this->defaults[$key]
: $default;

return $this->getByManager($key, $value, $default);
}

/**
Expand All @@ -230,12 +234,12 @@ private function getDefaultValue($key, $default = null)
*/
private function getByManager($key, $value, $default = null)
{
if (0 === strpos($key, 'manager-') && \is_array($value)
&& (!isset($this->defaults[$key]) || !\is_array($this->defaults[$key]))) {
if (0 === strpos($key, 'manager-') && \is_array($value)) {
$manager = $manager = $this->get('manager', '');

$value = \array_key_exists($manager, $value)
? $value[$manager]
: $this->getDefaultValue($key, $default);
: $default;
}

return $value;
Expand Down
5 changes: 4 additions & 1 deletion Foxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class Foxy implements PluginInterface, EventSubscriberInterface
private static $defaultConfig = array(
'enabled' => true,
'manager' => 'npm',
'manager-version' => null,
'manager-version' => array(
'npm' => '>=5.0.0',
'yarn' => '>=1.0.0',
),
'manager-bin' => null,
'manager-options' => null,
'manager-install-options' => null,
Expand Down

0 comments on commit 847ebd3

Please sign in to comment.