maatify / data-repository
Unified repository abstraction layer normalizing MySQL, MongoDB, and Redis real drivers and fake drivers.
Installs: 0
Dependents: 0
Suggesters: 1
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 1
pkg:composer/maatify/data-repository
Requires
- php: >=8.4
- maatify/bootstrap: ^1.0
- maatify/common: ^1.0
- maatify/data-adapters: ^1.0
- maatify/psr-logger: ^1.0
Requires (Dev)
- doctrine/dbal: ^4.3
- friendsofphp/php-cs-fixer: ^3.60
- maatify/data-fakes: ^1.0
- mongodb/mongodb: ^2.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- predis/predis: ^2.3
Suggests
- ext-mongodb: Required for MongoAdapter.
- ext-pdo: Required for MySQLAdapter (PDO driver).
- ext-redis: High-performance RedisAdapter.
- doctrine/dbal: Optional advanced SQL driver for MySQLDbalAdapter.
- mongodb/mongodb: Needed if using MongoAdapter.
- predis/predis: Fallback when ext-redis is unavailable.
- dev-main
- v1.0.0
- dev-improve-test-coverage
- dev-phase-29-coverage-update
- dev-improve-test-coverage-v1
- dev-phase30-release-v1.0.0
- dev-update-readme-docs
- dev-docs-readme-anchors-fix
- dev-documentation-links-update
- dev-update-examples-md
- dev-phase29-changelog-update
- dev-docs-fix-readme-quickstart
- dev-docs-update-readme
- dev-phase29-dx-docs-fix-hydration
- dev-phase29-dx-docs-fix
- dev-phase29-dx-docs
- dev-phase28-phpstan-generics-finalize-v3
- dev-phase28-phpstan-generics-finalize-v2
- dev-phase28-phpstan-generics-finalize
- dev-phase28-phpstan-generics-test-fix-final-v5
- dev-phase28-phpstan-generics-test-fix-final-v4
- dev-phase28-phpstan-generics-test-fix-final-v3
- dev-phase28-phpstan-generics-test-fix-final-v2
- dev-phase28-phpstan-generics-test-fix-final
- dev-phase28-phpstan-generics-final
- dev-phase28-phpstan-generics-tests-fix
- dev-phase28-phpstan-generics-fix-2
- dev-phase28-phpstan-generics-fix
- dev-phase28-phpstan-generics
- dev-phase27-options-config
- dev-update-root-readme-phase26
- dev-update-full-readme-phase26
- dev-phase26-api-tightening-v4
- dev-phase26-api-tightening-v3
- dev-phase26-api-tightening-v2
- dev-phase26-api-tightening
- dev-feature/phase25-order-builders-v2
- dev-phase24-documentation-update
- dev-feature/phase25-order-builders
- dev-phase24-order-parser-extraction-v2
- dev-phase24-order-parser-extraction
- dev-phase23-filter-builders
- dev-release/phase22-artifacts
- dev-release/phase22-completion
- dev-feature/phase22-filter-parser-fix
- dev-feature/phase22-filter-parser
- dev-phase21-logger-decoupling-fixed-example
- dev-phase21-logger-decoupling-v6
- dev-phase21-logger-decoupling-final
- dev-phase21-logger-decoupling-v5
- dev-phase21-logger-decoupling-v4
- dev-phase21-logger-decoupling-v3
- dev-phase21-logger-decoupling-v2
- dev-phase21-logger-decoupling
- dev-phase20-sql-improvements-v4
- dev-phase20-sql-improvements-v3
- dev-phase20-sql-improvements-v2
- dev-phase20-sql-improvements
- dev-phase19-nosql-robustness-final
- dev-phase19-nosql-robustness-v3
- dev-phase19-nosql-robustness-v2
- dev-phase19-nosql-robustness
- dev-chore/update-roadmap-phases
- dev-feature/improve-code-coverage-fixed-v3
- dev-feature/improve-code-coverage-fixed-v2
- dev-feature/improve-code-coverage-fixed
- dev-feature/improve-code-coverage
- dev-coverage/fix-pagination-tests-final-v3
- dev-coverage/fix-pagination-tests-final-v2
- dev-coverage/fix-pagination-tests-final
- dev-coverage/fix-pagination-tests-v2
- dev-coverage/fix-pagination-tests
- dev-coverage/fix-pagination-dto
- dev-fix/redis-coverage-tests-v2
- dev-fix/redis-tests-initialization
- dev-fix/coverage-tests-phpstan
- dev-test/increase-coverage
- dev-feature/phase18-integration-matrix
- dev-phase17-hydrated-pagination-v3
- dev-phase17-hydrated-pagination-v2
- dev-phase17-hydrated-pagination
- dev-phase16-pagination-optimization
- dev-phase15-pagination-core
- dev-phase14-dto-mapping-v5
- dev-phase14-dto-mapping-v4
- dev-phase14-dto-mapping-v3
- dev-phase14-dto-mapping-v2
- dev-phase14-dto-mapping
- dev-feature/phase13-autocasting-v2
- dev-feature/phase13-autocasting
- dev-phase12-base-hydrator-v3
- dev-phase12-base-hydrator-v2
- dev-phase12-base-hydrator
- dev-phase-11-hydration-contract-v2
- dev-phase-11-hydration-contract
- dev-phase10-pagination-hooks
- dev-feature/phase9-ops-complete-final
- dev-feature/phase9-ops-complete
- dev-feature/phase9-ops-final-examples
- dev-fix/phase9-redis-inclusion
- dev-feature/phase9-ops-integration-final
- dev-feature/phase9-ops-integration
- dev-fix-phase6-example
- dev-coverage-improvements-v8
- dev-coverage-improvements-v7
- dev-coverage-improvements-v6
- dev-coverage-improvements-v5
- dev-coverage-improvements-v4
- dev-examples-update
- dev-coverage-improvements-v3
- dev-coverage-improvements-v2
- dev-coverage-improvements
- dev-phase8-crud-edge-cases-v3
- dev-phase8-crud-edge-cases-v2
- dev-phase8-crud-edge-cases
- dev-phase6-limits-offsets-changelog
- dev-phase7-result-normalization
- dev-phase6-limits-offsets-v2
- dev-phase6-limits-offsets-complete
- dev-phase6-limits-offsets-refined
- dev-phase6-limits-offsets
- dev-phase5-ordering
- dev-phase4-advanced-filtering
- dev-ci-doctor
This package is auto-updated.
Last update: 2025-12-08 14:17:08 UTC
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.
๐ 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