diff --git a/src/config.php b/src/config.php new file mode 100644 index 0000000..102b914 --- /dev/null +++ b/src/config.php @@ -0,0 +1,49 @@ +_env = $env; + + $config = include($file); + $this->_data = $this->getConfigForEnvironment($config); + } + + public function setModule($module) + { + if (!isset($this->_data['modules'][$module]['config'])) return; + $config = $this->_data['modules'][$module]['config']; + $config = $this->getConfigForEnvironment($config); + $this->_data = $this->mergeArray($this->_data,$config); + } + + private function getConfigForEnvironment($config) + { + $env = $this->_env; + $data = isset($config['shared']) ? $config['shared'] : array(); + + if (isset($config[$env])) $data = $this->mergeArray($data,$config[$env]); + + return $data; + } + + private function mergeArray($arr1, $arr2) + { + foreach($arr2 as $key => $value) + { + if(array_key_exists($key, $arr1) && is_array($value)) { + $arr1[$key] = $this->mergeArray($arr1[$key], $arr2[$key]); + } + else { + $arr1[$key] = $value; + } + } + + return $arr1; + } + +} diff --git a/src/node.php b/src/node.php new file mode 100644 index 0000000..d82ed85 --- /dev/null +++ b/src/node.php @@ -0,0 +1,58 @@ +_data = $data; + } + + public function __get($name) { + return $this->get($name); + } + + public function get($name) { + $val = isset($this->_data[$name]) ? $this->_data[$name] : null; + + if ($val == null) return null; + if (is_array($val)) { + if (isset($val[0])) { + return $val; + } else { + return new Node($val); + } + } + + return $val; + } + + public function has($name) { + return isset($this->_data[$name]); + } + + public function __isset($name) { + return $this->has($name); + } + + public function getData() { + return $this->_data; + } + + public function offsetExists($name) { + return $this->has($name); + } + + public function offsetGet($name) { + return $this->get($name); + } + + public function offsetSet($name,$value) { + return false; + } + + public function offsetUnset($name) { + return false; + } +} \ No newline at end of file