Skip to content

Commit 9eca109

Browse files
committed
feat: add ConnectionTypeEnum and ConnectionConfigDTO to support DSN-based resolution
- Introduced ConnectionTypeEnum for normalized adapter types - Added ConnectionConfigDTO to unify connection configuration structure - Updated internal documentation and prepared for DSN routing in data-adapters - Part of Phase 10 preparation (maatify/data-adapters)
1 parent 1517a02 commit 9eca109

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

src/DTO/ConnectionConfigDTO.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,64 @@
1818
* 🧩 **Class ConnectionConfigDTO**
1919
*
2020
* 🎯 **Purpose:**
21-
* Represents a standardized, immutable configuration Data Transfer Object (DTO)
22-
* for defining connection settings across supported adapters (MySQL, MongoDB, Redis, etc.).
21+
* Defines a unified, immutable Data Transfer Object (DTO) representing
22+
* connection parameters across all supported data adapters (MySQL, MongoDB, Redis, etc.).
2323
*
2424
* 🧠 **Key Features:**
25-
* - Provides a unified structure for DSN-based connection setup.
26-
* - Used for dependency injection and adapter factory initialization.
27-
* - Immutable (`readonly`) to ensure safe configuration integrity at runtime.
25+
* - Combines traditional DSN and discrete parameter forms (`host`, `port`, `database`, etc.).
26+
* - Enables flexible connection initialization for adapters and factories.
27+
* - Immutable (`readonly`) for configuration safety and predictability.
28+
* - Supports additional options (e.g., PDO attributes, timeouts, SSL settings).
2829
*
2930
* ✅ **Example Usage:**
3031
* ```php
3132
* use Maatify\Common\DTO\ConnectionConfigDTO;
3233
*
3334
* $config = new ConnectionConfigDTO(
3435
* dsn: 'mysql:host=127.0.0.1;dbname=maatify',
36+
* host: '127.0.0.1',
37+
* port: '3306',
3538
* user: 'root',
3639
* pass: 'secret',
40+
* database: 'maatify',
3741
* options: [
3842
* PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
3943
* ],
4044
* driver: 'pdo',
4145
* profile: 'production'
4246
* );
4347
* ```
48+
*
49+
* 🧱 **Use Cases:**
50+
* - Passed into adapter constructors for dynamic connection setup.
51+
* - Used by `DatabaseResolver` or dependency injection containers to build adapter instances.
52+
* - Supports multi-environment profiles (e.g., local, staging, production).
4453
*/
4554
final readonly class ConnectionConfigDTO
4655
{
4756
/**
4857
* 🧠 **Constructor**
4958
*
50-
* Defines the full connection configuration parameters.
59+
* Defines complete connection configuration properties, supporting both
60+
* DSN-based and parameter-based connection schemes.
5161
*
52-
* @param string $dsn Data Source Name string (e.g., `"mysql:host=127.0.0.1;dbname=test"`).
53-
* @param string|null $user Optional database username (if applicable).
54-
* @param string|null $pass Optional database password (if applicable).
55-
* @param array $options Optional adapter or driver-specific options.
56-
* @param string|null $driver Optional driver identifier (e.g., `"pdo"`, `"dbal"`, `"mysqli"`).
57-
* @param string|null $profile Optional connection profile name (useful for multi-env setups).
62+
* @param string|null $dsn Full connection string (e.g., `"mysql:host=127.0.0.1;dbname=maatify"`).
63+
* @param string|null $host Hostname or IP of the data source.
64+
* @param string|null $port Port number (string to maintain type consistency).
65+
* @param string|null $user Username credential for authentication.
66+
* @param string|null $pass Password credential for authentication.
67+
* @param string|null $database Target database name (if applicable).
68+
* @param array $options Adapter-specific or driver options (e.g., PDO attributes).
69+
* @param string|null $driver Driver type (e.g., `"pdo"`, `"dbal"`, `"mysqli"`, `"mongo"`, `"redis"`).
70+
* @param string|null $profile Optional configuration profile (e.g., `"local"`, `"production"`).
5871
*/
5972
public function __construct(
60-
public string $dsn,
73+
public ?string $dsn = null,
74+
public ?string $host = null,
75+
public ?string $port = null,
6176
public ?string $user = null,
6277
public ?string $pass = null,
78+
public ?string $database = null,
6379
public array $options = [],
6480
public ?string $driver = null,
6581
public ?string $profile = null,

0 commit comments

Comments
 (0)