Ver Fonte

dev 2021-04

Max F há 4 anos atrás
pai
commit
f65fab1c86
2 ficheiros alterados com 17 adições e 2 exclusões
  1. 10 2
      src/App.php
  2. 7 0
      src/Kernel.php

+ 10 - 2
src/App.php

@@ -211,7 +211,7 @@ class App
 	}
 
 
-	public static function getConfig($key=null)
+	public static function getConfig($key=null, $subkey=null)
 	{
 		$config = App::getData('config');
 		if (is_null($key)) {
@@ -222,7 +222,15 @@ class App
 			return null;
 		}
 
-		return $config[$key];
+		if (is_null($subkey)) {
+			return $config[$key];
+		}
+
+		if (empty($config[$key]) || !isset($config[$key][$subkey])) {
+			return null;
+		}
+
+		return $config[$key][$subkey];
 	}
 
 }

+ 7 - 0
src/Kernel.php

@@ -212,6 +212,10 @@ class Kernel
 			if (empty($dsn) && defined('DB_DSN')) {
 				$dsn = DB_DSN;
 			}
+			if (empty($dsn)) {
+				$dsn = App::getConfig('database', 'default');
+			}
+			//pre($config_database, 1);
 			return new \KarmaFW\Database\Sql\SqlDb($dsn);
 		});
 
@@ -291,6 +295,9 @@ class Kernel
 			if (empty($dsn) && defined('DB_DSN')) {
 				$dsn = DB_DSN;
 			}
+			if (empty($dsn)) {
+				$dsn = App::getConfig('database', $instance_name);
+			}
 			$instances[$instance_name] = new SqlDb($dsn);
 		}