Skip to content

Commit 19ba13d

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 c9cfb86 commit 19ba13d

4 files changed

Lines changed: 202 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,91 @@
33
All notable changes to **maatify/common** will be documented in this file.
44
This project follows [Semantic Versioning](https://semver.org/).
55

6+
## [1.0.3] – 2025-11-13
7+
8+
### 🧩 Connectivity Foundation — Introducing `ConnectionConfigDTO` & `ConnectionTypeEnum`
9+
10+
**Release Date:** 2025-11-13
11+
**Author:** [Mohamed Abdulalim (megyptm)](mailto:mohamed@maatify.dev)
12+
**License:** MIT
13+
**Organization:** [Maatify.dev](https://www.maatify.dev)
14+
15+
---
16+
17+
### ⚙️ Overview
18+
19+
This update introduces two new standardized components that will be used across all Maatify backend libraries:
20+
21+
* **`ConnectionConfigDTO`** — a readonly DTO that encapsulates driver-specific connection settings.
22+
* **`ConnectionTypeEnum`** — a unified enum for all supported connection types (`mysql`, `mongo`, `redis`).
23+
24+
These additions support the new DSN-based workflow planned in `maatify/data-adapters` (Phase 10)
25+
and enforce consistency across the Maatify ecosystem.
26+
27+
> “One connection model — shared across all libraries.”
28+
29+
---
30+
31+
### 🧩 Added
32+
33+
#### `Maatify\Common\DTO\ConnectionConfigDTO`
34+
35+
* Readonly object representing:
36+
37+
* `driver`
38+
* `dsn`
39+
* `user`
40+
* `pass`
41+
* `options`
42+
* `profile` (supports multiple DSN profiles in future releases)
43+
* Basis for profile-based DSN resolution in data-adapters.
44+
45+
#### `Maatify\Common\Enums\ConnectionTypeEnum`
46+
47+
* Defines consistent adapter identifiers:
48+
49+
* `MYSQL`
50+
* `MONGO`
51+
* `REDIS`
52+
53+
#### ✔ New Tests
54+
55+
* Added test suite:
56+
57+
* `tests/DTO/ConnectionConfigDTOTest.php`
58+
* `tests/Enums/ConnectionTypeEnumTest.php`
59+
* Verified:
60+
61+
* DTO immutability
62+
* Enum integrity
63+
* PSR-12 compliance
64+
65+
#### ✔ Documentation Update
66+
67+
* Updated `/docs/core/helpers.md`
68+
→ Added new section: **Connectivity Foundation**
69+
* Linked from main README under **Core Modules**
70+
71+
---
72+
73+
### 🧱 Architectural Impact
74+
75+
* Establishes a **shared foundation** for database configurations.
76+
* Required for **Phase 10** in `maatify/data-adapters` (string-based driver selection + DSN builder).
77+
* Ensures **cross-library consistency** for all future adapters and DI containers.
78+
79+
---
80+
81+
### 🧾 Changelog Snapshot
82+
83+
**v1.0.3 — 2025-11-13**
84+
85+
* Added: `ConnectionConfigDTO`
86+
* Added: `ConnectionTypeEnum`
87+
* Added: Tests for DTO & Enum
88+
* Updated: Docs with new Connectivity Foundation section
89+
* No breaking changes — Fully backward compatible
90+
691
---
792

893
## [1.0.2] – 2025-11-10

release-note.md

Whitespace-only changes.

src/DTO/ConnectionConfigDTO.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* @copyright ©2025 Maatify.dev
4+
* @Library maatify/common
5+
* @Project maatify:common
6+
* @author Mohamed Abdulalim (megyptm) <mohamed@maatify.dev>
7+
* @since 2025-11-13 16:17
8+
* @see https://www.maatify.dev Maatify.com
9+
* @link https://github.com/Maatify/common view project on GitHub
10+
* @note Distributed in the hope that it will be useful - WITHOUT WARRANTY.
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
namespace Maatify\Common\DTO;
16+
17+
/**
18+
* 🧩 **Class ConnectionConfigDTO**
19+
*
20+
* 🎯 **Purpose:**
21+
* Represents a standardized, immutable configuration Data Transfer Object (DTO)
22+
* for defining connection settings across supported adapters (MySQL, MongoDB, Redis, etc.).
23+
*
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.
28+
*
29+
* ✅ **Example Usage:**
30+
* ```php
31+
* use Maatify\Common\DTO\ConnectionConfigDTO;
32+
*
33+
* $config = new ConnectionConfigDTO(
34+
* dsn: 'mysql:host=127.0.0.1;dbname=maatify',
35+
* user: 'root',
36+
* pass: 'secret',
37+
* options: [
38+
* PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
39+
* ],
40+
* driver: 'pdo',
41+
* profile: 'production'
42+
* );
43+
* ```
44+
*/
45+
final readonly class ConnectionConfigDTO
46+
{
47+
/**
48+
* 🧠 **Constructor**
49+
*
50+
* Defines the full connection configuration parameters.
51+
*
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).
58+
*/
59+
public function __construct(
60+
public string $dsn,
61+
public ?string $user = null,
62+
public ?string $pass = null,
63+
public array $options = [],
64+
public ?string $driver = null,
65+
public ?string $profile = null,
66+
) {}
67+
}

src/Enums/ConnectionTypeEnum.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* @copyright ©2025 Maatify.dev
4+
* @Library maatify/common
5+
* @Project maatify:common
6+
* @author Mohamed Abdulalim (megyptm) <mohamed@maatify.dev>
7+
* @since 2025-11-13 16:18
8+
* @see https://www.maatify.dev Maatify.com
9+
* @link https://github.com/Maatify/common view project on GitHub
10+
* @note Distributed in the hope that it will be useful - WITHOUT WARRANTY.
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
namespace Maatify\Common\Enums;
16+
17+
/**
18+
* 🧩 **Enum ConnectionTypeEnum**
19+
*
20+
* 🎯 **Purpose:**
21+
* Defines the supported connection types across the Maatify ecosystem.
22+
* Used to standardize adapter selection and environment configuration references.
23+
*
24+
* 🧠 **Key Features:**
25+
* - Ensures strict typing for connection type values.
26+
* - Prevents magic strings in adapter logic.
27+
* - Facilitates polymorphic adapter resolution and dependency injection.
28+
*
29+
* ✅ **Example Usage:**
30+
* ```php
31+
* use Maatify\Common\Enums\ConnectionTypeEnum;
32+
*
33+
* $type = ConnectionTypeEnum::REDIS;
34+
*
35+
* if ($type === ConnectionTypeEnum::MYSQL) {
36+
* echo "Connecting to MySQL...";
37+
* }
38+
* ```
39+
*/
40+
enum ConnectionTypeEnum: string
41+
{
42+
/** 🔹 MySQL relational database connection type. */
43+
case MYSQL = 'mysql';
44+
45+
/** 🔹 MongoDB NoSQL database connection type. */
46+
case MONGO = 'mongo';
47+
48+
/** 🔹 Redis in-memory data store connection type. */
49+
case REDIS = 'redis';
50+
}

0 commit comments

Comments
 (0)