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: 11
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/maatify/data-adapters
Requires
- php: >=8.4
- maatify/bootstrap: ^1.0
- maatify/common: ^1.0
Requires (Dev)
- doctrine/dbal: ^4.3
- maatify/rate-limiter: dev-main
- mongodb/mongodb: ^2.0
- phpunit/phpunit: ^10.0
- predis/predis: ^2.3
- vlucas/phpdotenv: ^5.6
Suggests
- ext-mongodb: Required for MongoAdapter
- ext-pdo: Required for MySQLAdapter (PDO driver)
- ext-redis: or high-performance native RedisAdapter
- doctrine/dbal: Optional advanced SQL driver for MySQLDbalAdapter
- mongodb/mongodb: Required only if you plan to use MongoAdapter for MongoDB integration.
- predis/predis: Used as fallback when ext-redis is unavailable
README
π¦ 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
- Introduction:
docs/README.intro.md - Environment Reference:
docs/env.md - Telemetry:
docs/telemetry.md - Architecture:
docs/architecture.md - Multi-Profile MySQL:
docs/mysql-profiles.md - Usage Examples:
docs/USAGE.md - Phases:
docs/README.roadmap.md - Changelog:
CHANGELOG.md
π Related Maatify Libraries
- maatify/common
- maatify/psr-logger
- maatify/bootstrap
- maatify/rate-limiter
- maatify/security-guard
- maatify/mongo-activity
π 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