Skip to content

Commit

Permalink
Refactor method names
Browse files Browse the repository at this point in the history
  • Loading branch information
tomphp committed Mar 11, 2015
1 parent e5d8701 commit c97a638
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class ConfigServiceProvider extends ServiceProvider
*/
private $config;

/**
* @var string
*/
private $prefix;

/**
* @var string
*/
Expand All @@ -22,11 +27,12 @@ class ConfigServiceProvider extends ServiceProvider
*/
public function __construct(array $config, $prefix = 'config', $separator = '.')
{
$this->prefix = $prefix;
$this->separator = $separator;

$config = $this->expandSubGroups($config);

$this->provides = $this->addPrefix($config, $prefix);
$this->provides = $this->getKeys($config);

$this->config = array_combine($this->provides, array_values($config));
}
Expand Down Expand Up @@ -78,17 +84,27 @@ private function expandSubGroup($key, $value)
*
* @return array
*/
private function addPrefix(array $config, $prefix)
private function getKeys(array $config)
{
if (!empty($prefix)) {
$prefix .= $this->separator;
$keys = array_keys($config);

if (!empty($this->prefix)) {
$keys = $this->addPrefix($keys);
}

return $keys;
}

/**
* @return array
*/
private function addPrefix(array $keys)
{
return array_map(
function ($key) use ($prefix) {
return "$prefix$key";
function ($key) {
return $this->prefix . $this->separator . $key;
},
array_keys($config)
$keys
);
}
}

0 comments on commit c97a638

Please sign in to comment.