maatify/data-adapters

Unified data connectivity and diagnostics layer for Redis, MySQL, and MongoDB with automatic fallback recovery, telemetry-ready metrics, and environment auto-detection. Forms the foundation of the Maatify Data Infrastructure.

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/maatify/data-adapters

v1.1.0 2025-11-15 20:28 UTC

This package is auto-updated.

Last update: 2025-11-15 20:58:40 UTC


README

Maatify.dev

Version PHP Build

Monthly Downloads Total Downloads

Stars License Status Code Quality

Changelog Security

πŸ“¦ maatify/data-adapters

Unified Data Connectivity & Diagnostics Layer

πŸ”— Ψ¨Ψ§Ω„ΨΉΨ±Ψ¨ΩŠ πŸ‡ΈπŸ‡¦

🧭 Overview

maatify/data-adapters is a unified, framework-agnostic layer for managing Redis, MongoDB,
and MySQL connections with centralized diagnostics and auto-detection.
It serves as the core data layer of the Maatify Ecosystem.

βš™οΈ Installation

composer require maatify/data-adapters

Requirements:
β€’ PHP β‰₯ 8.4
β€’ Redis (phpredis recommended β€” Predis auto-fallback)
β€’ MongoDB extension (optional)
β€’ PDO MySQL required (DBAL optional)

✨ Features

  • Unified configuration engine (Phase 13)
  • Registry β†’ DSN β†’ Legacy priority system
  • Fully unified config builders for MySQL / MongoDB / Redis
  • Multi-profile MySQL & MongoDB (unlimited profiles)
  • Redis unified builder (future multi-profile ready)
  • Centralized diagnostics & health checks

πŸ”₯ New in Phase 13 β€” Unified Configuration Architecture

Phase 13 finalizes the unified configuration engine across all adapters.

βœ” Global Configuration Priority

Registry β†’ DSN β†’ Legacy (Deprecated)
This applies consistently to MySQL, MongoDB, and Redis.

βœ” Unified Builder Behavior (Final)

All builders now:

  • Return fully normalized configuration objects
  • Use identical DSN parsing rules
  • Support unlimited profiles (mysql.main, mongo.logs, …)
  • Merge configuration with the same priority logic
  • Expose driver + profile metadata

βœ” Registry JSON Support

A new registry.json file allows runtime overrides:

{
  "mysql": {
    "main": { "user": "override_user" }
  },
  "redis": {
    "cache": { "host": "10.0.0.1", "port": 6380 }
  }
}

This overrides DSN & legacy variables automatically.

βœ” Redis Builder Unified

The Redis builder has been rewritten to match MySQL/Mongo logic and is now future-ready for multi-profile support.

🧩 Compatibility

Fully framework-agnostic.
Optional auto-wiring available via maatify/bootstrap.

  • Fully compatible with the new Phase 13 unified configuration engine
  • Supports runtime overrides through registry.json

πŸš€ Quick Usage (Updated for Phase 13 β€” Unified Config Engine)

use Maatify\DataAdapters\Core\EnvironmentConfig;
use Maatify\DataAdapters\Core\DatabaseResolver;

$config   = new EnvironmentConfig(__DIR__);

// Phase 13: Registry β†’ DSN β†’ Legacy
$resolver = new DatabaseResolver($config);

// ------------------------------------
// 🟣 MySQL β€” Multi-Profile (Phase 13)
// ------------------------------------
$mainDb = $resolver->resolve("mysql.main", autoConnect: true);
$logsDb = $resolver->resolve("mysql.logs");
$billingDb = $resolver->resolve("mysql.billing"); // unlimited profiles

$stmt = $mainDb->getConnection()->query("SELECT 1");
echo $stmt->fetchColumn(); // 1

// ------------------------------------
// 🟒 MongoDB β€” Multi-Profile (Phase 13)
// ------------------------------------
$mongoMain = $resolver->resolve("mongo.main", autoConnect: true);
$mongoLogs = $resolver->resolve("mongo.logs");

$db     = $mongoMain->getConnection()->selectDatabase("admin");
$ok     = $db->command(["ping" => 1])->toArray()[0]["ok"];

echo $ok; // 1

// ------------------------------------
// πŸ”΄ Redis β€” Unified Builder (Phase 13)
// ------------------------------------
$redis = $resolver->resolve("redis.cache", autoConnect: true);
$redis->getConnection()->set("key", "maatify");
echo $redis->getConnection()->get("key"); // maatify

// ------------------------------------
// πŸ” Debug Final Merged Configuration
// (Phase 13 unified DTO output)
// ------------------------------------
print_r(
    $mainDb->debugConfig()->toArray()
);

/*
Output example:
[
    "dsn"      => "mysql://user:pass@127.0.0.1:3306/main",
    "host"     => "127.0.0.1",
    "port"     => "3306",
    "user"     => "user",
    "pass"     => "pass",
    "database" => "main",
    "driver"   => "pdo",
    "profile"  => "main"
]
*/

// ------------------------------------
// πŸ“¦ Registry Override Example
// registry.json:
// {
//   "mysql": { "main": { "user": "override_user" } }
// }
// ------------------------------------

$mainDbFromRegistry = $resolver->resolve("mysql.main");
print_r($mainDbFromRegistry->debugConfig()->user);
// override_user

🧩 Diagnostics & Health Checks

All adapters include self-diagnostic capabilities and unified health reporting.

use Maatify\DataAdapters\Diagnostics\DiagnosticService;

$diagnostic = new DiagnosticService($config, $resolver);
echo $diagnostic->toJson();

Example Output

{
  "diagnostics": [
    {"adapter": "redis", "connected": true},
    {"adapter": "mongo", "connected": true},
    {"adapter": "mysql", "connected": true}
  ]
}

πŸ§ͺ Testing

vendor/bin/phpunit

Coverage: β‰ˆ 93%
Status: βœ… All tests passing (DSN, registry, multi-profile, diagnostics, metrics)
Suites:

  • Unit Tests
  • Integration Tests
  • DSN Parsing Tests
  • Registry Merge Tests
  • Multi-Profile MySQL & MongoDB Tests
  • Redis Builder Tests
  • Diagnostics & Metrics Tests

πŸ“š Documentation

πŸ”— Related Maatify Libraries

πŸ”— Full documentation & release notes: see /docs/README.full.md

πŸͺͺ License

MIT license Β© Maatify.dev
You’re free to use, modify, and distribute this library with attribution.

πŸ‘€ Author

Mohamed Abdulalim β€” Backend Lead & Technical Architect
πŸ”— https://www.maatify.dev | βœ‰οΈ mohamed@maatify.dev

🀝 Contributors

Special thanks to the Maatify.dev engineering team and open-source contributors.

Built with ❀️ by Maatify.dev β€” Unified Ecosystem for Modern PHP Libraries