maatify/data-repository
Composer 安装命令:
composer require maatify/data-repository
包简介
Unified repository abstraction layer normalizing MySQL, MongoDB, and Redis real drivers and fake drivers.
关键字:
README 文档
README
Unified repository abstraction layer normalizing MySQL, MongoDB, and Redis real & fake drivers.
🚀 Overview
Maatify Data Repository separates domain logic from database-specific implementations and provides a unified API supporting:
- Real Drivers (
maatify/data-adapters) - Fake Drivers (
maatify/data-fakes)
Why this library?
- Zero driver lock-in
- Deterministic testing without Docker
- Static analysis with PHPStan Level Max
- Unified CRUD/Filters/Pagination across MySQL, MongoDB, and Redis
Supported Drivers
| Type | Real Drivers | Fake Drivers |
|---|---|---|
| MySQL | PDO / Doctrine DBAL | In-memory SQL-like tables |
| MongoDB | mongodb/mongodb | In-memory BSON-like collections |
| Redis | redis / predis | In-memory key-value store |
📦 Installation
composer require maatify/data-repository
⚡ Quick Usage
1) Create a Repository
use Maatify\DataRepository\Base\BaseMySQLRepository; /** @extends BaseMySQLRepository<array> */ class UserRepository extends BaseMySQLRepository { protected string $tableName = 'users'; }
2) Use in Production (Real Adapter)
$resolver = new DatabaseResolver(new EnvironmentConfig(__DIR__)); $adapter = $resolver->resolve('mysql.main'); $repo = new UserRepository($adapter); $users = $repo->findBy(['active' => 1]);
3) Use in Testing (Fake Adapter)
$storage = new FakeStorageLayer(); $adapter = new FakeMySQLAdapter($storage); $storage->seed('users', [ ['id' => 1, 'active' => 1, 'name' => 'Alice'], ]); $repo = new UserRepository($adapter); $repo->findBy(['active' => 1]); // Alice
💎 Hydration & DTOs
class UserDto { public int $id; public string $name; } /** @extends BaseHydrator<UserDto> */ class UserHydrator extends BaseHydrator {} $repo->setHydrator(new UserHydrator()); $user = $repo->findObject(1);
🧩 Key Features
- Generic CRUD:
find,findBy,findOneBy,insert,update,delete,count,paginate. - Advanced Filtering:
IN,LIKE, ranges (>,<),IS NULL. - Sorting: Multi-column
orderBynormalized across drivers. - Pagination: Standardized
paginate()withPaginationResultDTO. - Hydration: Transform arrays to DTOs via
HydratorInterface. - Strict Validation: Prevents invalid offsets, limits, or types.
- Static Analysis: Fully Generic-aware (
@template T) for PHPStan Level Max.
🛑 MongoDB ObjectId Casting Rules
Important: To ensure predictability, this library enforces strict rules for MongoDB ID casting.
- Casting is allowed ONLY in
find(id) - 24-char hex strings are cast ONLY in
find(id) findBy,paginate, and filters NEVER cast automatically- Explicit
new ObjectId(...)is required in filters
Positive Example (Casting happens):
// Automatically converts string "507f1f77bcf86cd799439011" to ObjectId $repo->find("507f1f77bcf86cd799439011");
Negative Example (No casting happens):
// Remains a literal string "507f1f77bcf86cd799439011" $repo->findBy(['custom_id' => "507f1f77bcf86cd799439011"]);
📄 Documentation
📚 Development History & Phase Details
The development of this library follows a strict phase-based roadmap.
- Phase 1: Bootstrap
- Phase 3: Generic CRUD
- Phase 15: Pagination
- Phase 16: Pagination Optimization
- Phase 17: Hydrated Pagination
- Phase 20: SQL & Filter Improvements
- Phase 21: Architecture Decoupling
- Phase 22: FilterParser Extraction
- Phase 26: Public API Tightening
- Phase 28: PHPStan Generics
- Phase 29: Developer Experience
📚 Development History & Phase Details
Click to expand
This library evolves through a strict phase-based roadmap.
Major Completed Phases
- Phase 1 – Bootstrap & Foundation
- Phase 3 – Generic CRUD
- Phase 15–17 – Pagination Improvements & Hydration
- Phase 20 – SQL & Filter Enhancements
- Phase 21 – Architecture Decoupling
- Phase 22 – FilterParser Extraction
- Phase 26 – Public API Tightening
- Phase 28 – PHPStan Generics
- Phase 29 – Developer Experience
Full details available in docs/phases/.
🧱 Dependencies Overview
maatify/data-repository relies on Maatify core ecosystem + selected open-source libraries.
🧩 Maatify Ecosystem Dependencies
| Package | Description | Role |
|---|---|---|
| maatify/bootstrap | Environment loader, diagnostics, helpers | Powers .env and adapter bootstrapping |
| maatify/data-adapters | Real MySQL/Mongo/Redis adapters | Production database connectivity |
| maatify/data-fakes | Fake in-memory drivers | Deterministic, Docker-free testing |
🔌 Direct Open-Source Dependencies
| Library | Purpose |
|---|---|
| psr/log | Logging interface |
| phpunit/phpunit | Test suite |
| phpstan/phpstan | Static analysis |
| mongodb/mongodb | MongoDB driver |
| predis/predis / php-redis | Redis driver |
| doctrine/dbal (optional) | MySQL DBAL abstraction |
🔄 Indirect Dependencies (via bootstrap)
| Library | Purpose |
|---|---|
| vlucas/phpdotenv | .env loader |
| psr/container | DI compatibility |
Special thanks to the maintainers of these open-source libraries for providing the stable foundations that make this project possible. ❤️
🧪 Testing
composer test
Runs:
- Real vs Fake consistency checks
- Filter/Order parser tests
- Pagination & Hydration tests
- Architecture tests
- Coverage with Clover output
🪪 License
MIT License
© Maatify.dev — Free to use, modify, and distribute with attribution.
👤 Author
Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect — https://www.maatify.dev
🤝 Contributors
Special thanks to the Maatify.dev engineering team and all open-source contributors.
Your efforts help make this repository stronger and more reliable.
Contributions are always welcome!
Before opening a Pull Request, please make sure to read our
Contributing Guide and Code of Conduct.
Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries
maatify/data-repository 适用场景与选型建议
maatify/data-repository 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「mongodb」 「abstraction」 「mysql」 「predis」 「repository」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maatify/data-repository 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maatify/data-repository 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maatify/data-repository 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates Symfony2 documents, forms and CRUD
Microservice RPC through message queues.
Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
The CodeIgniter Redis package
ADOdb is a PHP database abstraction layer library
贝嘟分布式缓存扩展
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-23