diff --git a/system/engine/registry.php b/system/engine/registry.php index 1fc8e11..091aeb3 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -210,10 +210,42 @@ final class Registry { if(count($dataArray) > 1) { foreach($dataArray as $key => $value) { if($key !== "preferences") - self::$diOptions[$key] = isset(self::$diOptions[$key]) ? array_merge(self::$diOptions[$key], $value) : $value; + self::$diOptions[$key] = isset(self::$diOptions[$key]) ? self::array_merge_recursive_distinct(self::$diOptions[$key], $value) : $value; } } } + + private static function array_merge_recursive_distinct(array $array1, array $array2) + { + $merged = $array1; + + foreach ($array2 as $key => &$value) { + if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { + if (is_numeric(self::array_key_first($value))) { + // Concatenate arrays if both are numeric arrays (lists) + $merged[$key] = array_merge($merged[$key], $value); + } else { + // Recursively merge associative arrays + $merged[$key] = self::array_merge_recursive_distinct($merged[$key], $value); + } + } else { + $merged[$key] = $value; + } + } + + return $merged; + } + + private static function array_key_first($arr){ + if (!function_exists('array_key_first')) { + foreach ($arr as $key => $unused) { + return $key; + } + return null; + } else { + return array_key_first($arr); + } + } /** * Adds DI preferences from a JSON file. @@ -254,6 +286,7 @@ final class Registry { * @return bool */ static public function isDIrouteChecked($route){ + $route = strtolower($route); return isset(self::$diCheckedRoutes[$route]); } @@ -263,6 +296,7 @@ final class Registry { * @return true */ static public function addDIrouteChecked($route){ + $route = strtolower($route); self::$diCheckedRoutes[$route] = true; return self::$diCheckedRoutes[$route]; } @@ -357,7 +391,7 @@ final class Registry { * @throws \Exception * @throws \Phacil\Framework\Exception */ - static public function returnArgumentType($type, $argumentValue) { + private static function returnArgumentType($type, $argumentValue) { switch ($type) { case 'object': return self::getInstance($argumentValue); @@ -367,9 +401,6 @@ final class Registry { $object = array_map(function($value){ return self::getInstance($value); }, $argumentValue); - /* foreach($argumentValue as $objectValue) { - $object[] = self::getInstance($objectValue); - } */ return $object; break;