From c97a638bfe16514ce77443c96decd611dc5b4b9e Mon Sep 17 00:00:00 2001 From: Tom Oram Date: Wed, 11 Mar 2015 22:46:13 +0000 Subject: [PATCH] Refactor method names --- src/ConfigServiceProvider.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ConfigServiceProvider.php b/src/ConfigServiceProvider.php index 7949b73..5458395 100644 --- a/src/ConfigServiceProvider.php +++ b/src/ConfigServiceProvider.php @@ -11,6 +11,11 @@ class ConfigServiceProvider extends ServiceProvider */ private $config; + /** + * @var string + */ + private $prefix; + /** * @var string */ @@ -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)); } @@ -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 ); } }