From c13b54da1de36c1db6cdb9d380867094c580c997 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 27 Dec 2016 13:29:03 +0200 Subject: [PATCH] add local config --- .gitignore | 1 + src/lib/config.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index db4daf5..1d4cec9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /www-backend/* /www-arktika/list_images/* .idea +/src/config/global-local.php \ No newline at end of file diff --git a/src/lib/config.php b/src/lib/config.php index 9cfdcf8..388cdae 100644 --- a/src/lib/config.php +++ b/src/lib/config.php @@ -32,7 +32,10 @@ namespace */ public function __construct() { - $this->config = require( ROOT_PATH.'config/global.php' ); + $this->config = self::merge( + require( ROOT_PATH.'config/global.php' ), + require( ROOT_PATH.'config/global-local.php' ) + ); } /////////////////////////////////////////////////////////////////////// @@ -270,6 +273,31 @@ namespace { return ROOT_PATH.'log/'; } + + + public static function merge($a, $b) + { + $args = func_get_args(); + $res = array_shift($args); + while (!empty($args)) { + $next = array_shift($args); + foreach ($next as $k => $v) { + if (is_int($k)) { + if (isset($res[$k])) { + $res[] = $v; + } else { + $res[$k] = $v; + } + } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) { + $res[$k] = self::merge($res[$k], $v); + } else { + $res[$k] = $v; + } + } + } + + return $res; + } /////////////////////////////////////////////////////////////////////// } -- libgit2 0.21.4