Skip to content

Commit

Permalink
Refactor createCacheHostsConfig
Browse files Browse the repository at this point in the history
Make it a little more simple
  • Loading branch information
renttek committed Sep 30, 2017
1 parent 4b748cf commit 010097d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions setup/src/Magento/Setup/Model/ConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,34 @@ public function createModeConfig()
public function createCacheHostsConfig(array $data)
{
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);

if (isset($data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS])) {
$hostData = explode(',', $data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS]);
$hosts = [];
foreach ($hostData as $data) {
$dataArray = explode(':', trim($data));
$host = [];
$host['host'] = $dataArray[0];
if (isset($dataArray[1])) {
$host['port'] = $dataArray[1];
}
$hosts[] = $host;
}
$hosts = explode(',', $data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS]);
$hosts = array_map([$this, 'mapHostData'], $hosts);
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS, $hosts);
}

$configData->setOverrideWhenSave(true);
return $configData;
}

/**
* Splits host data to host and port and returns them as an assoc. array.
*
* @param string $hostData
*
* @return array
*/
private function mapHostData($hostData)
{
list($host, $port) = explode(':', trim($hostData));

$tmp = ['host' => $host];

if ($port !== null) {
$tmp['port'] = $port;
}

return $tmp;
}
}

0 comments on commit 010097d

Please sign in to comment.