|
18 | 18 | * 🧩 **Class ConnectionConfigDTO** |
19 | 19 | * |
20 | 20 | * 🎯 **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.). |
23 | 23 | * |
24 | 24 | * 🧠 **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). |
28 | 29 | * |
29 | 30 | * ✅ **Example Usage:** |
30 | 31 | * ```php |
31 | 32 | * use Maatify\Common\DTO\ConnectionConfigDTO; |
32 | 33 | * |
33 | 34 | * $config = new ConnectionConfigDTO( |
34 | 35 | * dsn: 'mysql:host=127.0.0.1;dbname=maatify', |
| 36 | + * host: '127.0.0.1', |
| 37 | + * port: '3306', |
35 | 38 | * user: 'root', |
36 | 39 | * pass: 'secret', |
| 40 | + * database: 'maatify', |
37 | 41 | * options: [ |
38 | 42 | * PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
39 | 43 | * ], |
40 | 44 | * driver: 'pdo', |
41 | 45 | * profile: 'production' |
42 | 46 | * ); |
43 | 47 | * ``` |
| 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). |
44 | 53 | */ |
45 | 54 | final readonly class ConnectionConfigDTO |
46 | 55 | { |
47 | 56 | /** |
48 | 57 | * 🧠 **Constructor** |
49 | 58 | * |
50 | | - * Defines the full connection configuration parameters. |
| 59 | + * Defines complete connection configuration properties, supporting both |
| 60 | + * DSN-based and parameter-based connection schemes. |
51 | 61 | * |
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"`). |
58 | 71 | */ |
59 | 72 | public function __construct( |
60 | | - public string $dsn, |
| 73 | + public ?string $dsn = null, |
| 74 | + public ?string $host = null, |
| 75 | + public ?string $port = null, |
61 | 76 | public ?string $user = null, |
62 | 77 | public ?string $pass = null, |
| 78 | + public ?string $database = null, |
63 | 79 | public array $options = [], |
64 | 80 | public ?string $driver = null, |
65 | 81 | public ?string $profile = null, |
|
0 commit comments