derafu / repository
Derafu: Repository - Lightweight File Data Source Management for PHP
dev-main
2025-02-17 20:25 UTC
Requires
- php: ^8.3
- derafu/config: dev-main
- derafu/support: dev-main
- psr/simple-cache: ^3.0
Requires (Dev)
- ext-xdebug: *
- friendsofphp/php-cs-fixer: ^3.63
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^11.4
- symfony/yaml: ^7.2
This package is auto-updated.
Last update: 2025-02-17 20:28:01 UTC
README
A lightweight, flexible PHP library for managing data repositories with multiple data sources and seamless integration with PHP frameworks.
Why Derafu\Repository?
🚀 Simplified Data Management
Traditional PHP data repositories often:
- Are tightly coupled to specific storage mechanisms.
- Require complex configuration.
- Lack flexibility across different data sources.
🔥 What Makes Derafu\Repository Unique?
Features
- ✅ Multiple Data Source Support – Load data from PHP arrays, JSON, YAML files.
- ✅ Generic Entity Handling – Work with any type of data structure.
- ✅ Flexible Querying – Find, filter, and order data with ease.
- ✅ Doctrine Collections Compatible – Use Doctrine Criteria for advanced filtering.
- ✅ Zero Heavy Dependencies – Lightweight and performance-focused.
- ✅ PHP 8+ Ready – Leverages modern PHP features.
Installation
Install via Composer:
composer require derafu/repository
Basic Usage
use Derafu\Repository\Repository; // Load data from a PHP file or array. $data = [ 'products' => [ 'prod-001' => [ 'name' => 'Laptop XPS', 'category' => 'computers', 'price' => 1299.99 ], // More products... ] ]; // Create a repository. $repository = new Repository($data, idAttribute: 'id'); // Find all products. $allProducts = $repository->findAll(); // Find products by criteria. $computerProducts = $repository->findBy([ 'category' => 'computers' ]); // Find a single product. $laptop = $repository->findOneBy([ 'name' => 'Laptop XPS' ]);
Advanced Usage with Doctrine Criteria
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Order; // Advanced filtering with Doctrine Criteria. $expensiveProducts = $repository->findByCriteria( Criteria::create() ->where(Criteria::expr()->gt('price', 1000)) ->orderBy(['price' => Order::Descending]) );
Supported Data Sources
- PHP Arrays.
- PHP Files returning arrays.
- JSON Files.
- YAML Files.
Performance Considerations
- Optimized for small to medium-sized datasets.
- In-memory data management.
- Recommended for configuration, lookup tables, and static data.
Contributing
Contributions are welcome! Feel free to submit a Pull Request.
License
This library is licensed under the MIT License. See the LICENSE
file for more details.