From 6c93a0de1499dcb86f327c08e17abc26e850de26 Mon Sep 17 00:00:00 2001 From: k1b3r Date: Thu, 16 Apr 2026 20:26:32 -0600 Subject: [PATCH 1/3] fix: Required database configuration key is missing bug --- .../database/src/Config/DatabaseConfig.php | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/database/src/Config/DatabaseConfig.php b/packages/database/src/Config/DatabaseConfig.php index eccda9bb..98ab9add 100644 --- a/packages/database/src/Config/DatabaseConfig.php +++ b/packages/database/src/Config/DatabaseConfig.php @@ -48,25 +48,32 @@ public function __construct( $config = require $configPath; + $defaultConnection = $config['default'] ?? null; + if ($defaultConnection === null || !isset($config['connections'][$defaultConnection])) { + throw ConfigurationException::missingRequiredKey('default'); + } + + $connectionConfig = $config['connections'][$defaultConnection]; + $requiredKeys = ['driver', 'host', 'port', 'database', 'username', 'password']; foreach ($requiredKeys as $key) { - if (!array_key_exists($key, $config)) { + if (!array_key_exists($key, $connectionConfig)) { throw ConfigurationException::missingRequiredKey($key); } } - $this->driver = $config['driver']; - $this->host = $config['host']; - $this->port = $config['port']; - $this->database = $config['database']; - $this->username = $config['username']; - $this->password = $config['password']; - $this->sslMode = $config['sslmode'] ?? null; - $this->sslRootCert = $config['ssl_ca'] ?? null; - $this->sslVerifyServerCert = $config['ssl_verify_server_cert'] ?? ($this->sslRootCert !== null); - $this->sslCert = $config['ssl_cert'] ?? null; - $this->sslKey = $config['ssl_key'] ?? null; + $this->driver = $connectionConfig['driver']; + $this->host = $connectionConfig['host']; + $this->port = $connectionConfig['port']; + $this->database = $connectionConfig['database']; + $this->username = $connectionConfig['username']; + $this->password = $connectionConfig['password']; + $this->sslMode = $connectionConfig['sslmode'] ?? null; + $this->sslRootCert = $connectionConfig['ssl_ca'] ?? null; + $this->sslVerifyServerCert = $connectionConfig['ssl_verify_server_cert'] ?? ($this->sslRootCert !== null); + $this->sslCert = $connectionConfig['ssl_cert'] ?? null; + $this->sslKey = $connectionConfig['ssl_key'] ?? null; if ($this->sslCert !== null && $this->sslKey === null) { throw ConfigurationException::incompleteSslKeyPair('ssl_cert', 'ssl_key'); From 203faac0e2ed05ef1fb89b3f28cffb6f2b65341b Mon Sep 17 00:00:00 2001 From: Mark Shust Date: Fri, 17 Apr 2026 08:05:02 -0400 Subject: [PATCH 2/3] Revert "fix: Required database configuration key is missing bug" This reverts commit 6c93a0de1499dcb86f327c08e17abc26e850de26. --- .../database/src/Config/DatabaseConfig.php | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/database/src/Config/DatabaseConfig.php b/packages/database/src/Config/DatabaseConfig.php index 98ab9add..eccda9bb 100644 --- a/packages/database/src/Config/DatabaseConfig.php +++ b/packages/database/src/Config/DatabaseConfig.php @@ -48,32 +48,25 @@ public function __construct( $config = require $configPath; - $defaultConnection = $config['default'] ?? null; - if ($defaultConnection === null || !isset($config['connections'][$defaultConnection])) { - throw ConfigurationException::missingRequiredKey('default'); - } - - $connectionConfig = $config['connections'][$defaultConnection]; - $requiredKeys = ['driver', 'host', 'port', 'database', 'username', 'password']; foreach ($requiredKeys as $key) { - if (!array_key_exists($key, $connectionConfig)) { + if (!array_key_exists($key, $config)) { throw ConfigurationException::missingRequiredKey($key); } } - $this->driver = $connectionConfig['driver']; - $this->host = $connectionConfig['host']; - $this->port = $connectionConfig['port']; - $this->database = $connectionConfig['database']; - $this->username = $connectionConfig['username']; - $this->password = $connectionConfig['password']; - $this->sslMode = $connectionConfig['sslmode'] ?? null; - $this->sslRootCert = $connectionConfig['ssl_ca'] ?? null; - $this->sslVerifyServerCert = $connectionConfig['ssl_verify_server_cert'] ?? ($this->sslRootCert !== null); - $this->sslCert = $connectionConfig['ssl_cert'] ?? null; - $this->sslKey = $connectionConfig['ssl_key'] ?? null; + $this->driver = $config['driver']; + $this->host = $config['host']; + $this->port = $config['port']; + $this->database = $config['database']; + $this->username = $config['username']; + $this->password = $config['password']; + $this->sslMode = $config['sslmode'] ?? null; + $this->sslRootCert = $config['ssl_ca'] ?? null; + $this->sslVerifyServerCert = $config['ssl_verify_server_cert'] ?? ($this->sslRootCert !== null); + $this->sslCert = $config['ssl_cert'] ?? null; + $this->sslKey = $config['ssl_key'] ?? null; if ($this->sslCert !== null && $this->sslKey === null) { throw ConfigurationException::incompleteSslKeyPair('ssl_cert', 'ssl_key'); From 5c31797096d939385e9e57d77f8329b02a41c142 Mon Sep 17 00:00:00 2001 From: Mark Shust Date: Fri, 17 Apr 2026 08:06:10 -0400 Subject: [PATCH 3/3] docs: fix database config examples to use flat format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docs showed a Laravel-style nested `default` + `connections` format that Marko doesn't use. DatabaseConfig expects a flat array, consistent with all other package configs (cache, session, mail, log, etc.). This was the root cause of #32 — users following the docs would get "Required database configuration key 'driver' is missing". Co-Authored-By: k1b3r Co-Authored-By: Claude Opus 4.6 (1M context) --- .../docs/getting-started/configuration.md | 19 ++++++--------- docs/src/content/docs/guides/database.md | 17 +++++-------- docs/src/content/docs/packages/config.md | 24 +++++++------------ 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/docs/src/content/docs/getting-started/configuration.md b/docs/src/content/docs/getting-started/configuration.md index 0c74c2ac..af7ed3a6 100644 --- a/docs/src/content/docs/getting-started/configuration.md +++ b/docs/src/content/docs/getting-started/configuration.md @@ -15,17 +15,12 @@ Configuration lives in PHP files that return arrays: declare(strict_types=1); return [ - 'default' => env('DB_CONNECTION', 'pgsql'), - 'connections' => [ - 'pgsql' => [ - 'driver' => 'pgsql', - 'host' => env('DB_HOST', 'localhost'), - 'port' => (int) env('DB_PORT', '5432'), - 'database' => env('DB_DATABASE', 'marko'), - 'username' => env('DB_USERNAME', 'marko'), - 'password' => env('DB_PASSWORD', ''), - ], - ], + 'driver' => 'pgsql', + 'host' => env('DB_HOST', 'localhost'), + 'port' => (int) env('DB_PORT', '5432'), + 'database' => env('DB_DATABASE', 'marko'), + 'username' => env('DB_USERNAME', 'marko'), + 'password' => env('DB_PASSWORD', ''), ]; ``` @@ -48,7 +43,7 @@ class DatabaseService public function getHost(): string { - return $this->configRepository->getString('database.connections.pgsql.host'); + return $this->configRepository->getString('database.host'); } } ``` diff --git a/docs/src/content/docs/guides/database.md b/docs/src/content/docs/guides/database.md index b0918dde..e9c7399c 100644 --- a/docs/src/content/docs/guides/database.md +++ b/docs/src/content/docs/guides/database.md @@ -19,17 +19,12 @@ Configure your connection in `config/database.php`: declare(strict_types=1); return [ - 'default' => env('DB_CONNECTION', 'pgsql'), - 'connections' => [ - 'pgsql' => [ - 'driver' => 'pgsql', - 'host' => env('DB_HOST', 'localhost'), - 'port' => (int) env('DB_PORT', '5432'), - 'database' => env('DB_DATABASE', 'marko'), - 'username' => env('DB_USERNAME', 'marko'), - 'password' => env('DB_PASSWORD', ''), - ], - ], + 'driver' => 'pgsql', + 'host' => env('DB_HOST', 'localhost'), + 'port' => (int) env('DB_PORT', '5432'), + 'database' => env('DB_DATABASE', 'marko'), + 'username' => env('DB_USERNAME', 'marko'), + 'password' => env('DB_PASSWORD', ''), ]; ``` diff --git a/docs/src/content/docs/packages/config.md b/docs/src/content/docs/packages/config.md index e94c0443..78e62f96 100644 --- a/docs/src/content/docs/packages/config.md +++ b/docs/src/content/docs/packages/config.md @@ -126,32 +126,26 @@ if ($config->has('feature.experimental')) { Access nested configuration values using dot notation. The filename becomes the top-level key. -```php title="config/database.php" +```php title="config/mail.php" 'mysql', - 'connections' => [ - 'mysql' => [ - 'host' => 'localhost', - 'port' => 3306, - ], - 'pgsql' => [ - 'host' => 'localhost', - 'port' => 5432, - ], + 'driver' => 'smtp', + 'from' => [ + 'address' => 'hello@example.com', + 'name' => 'My App', ], ]; ``` ```php get('database.default'); // 'mysql' -$host = $config->get('database.connections.mysql.host'); // 'localhost' -$port = $config->get('database.connections.pgsql.port'); // 5432 +// Access nested values (filename "mail" is the top-level key) +$driver = $config->get('mail.driver'); // 'smtp' +$address = $config->get('mail.from.address'); // 'hello@example.com' +$name = $config->get('mail.from.name'); // 'My App' ``` ### Environment Variables