Download the PHP package resoul/data-reader without Composer
On this page you can find all versions of the php package resoul/data-reader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package data-reader
Advanced Usage
Data Validation and Filtering
Chaining Multiple Transformations
Working with Large Datasets
Custom Resource with Pagination
Testing
Unit Testing Example
Troubleshooting
Common Issues
1. Memory Exhaustion with Large Files
2. Character Encoding Issues
3. Invalid Data Handling
Roadmap
Version 1.0 (In Progress)
- [x] Complete ArrayData implementation
- [x] Add comprehensive error handling with custom exceptions
- [x] Implement XML and CSV output formats
- [x] Create BaseConfig class with field mapping and validation
- [x] Add factory methods for common use cases
- [ ] Add unit tests with PHPUnit
- [ ] Implement streaming support for large files (>100MB)
Version 1.1 (Planned)
- [ ] Add Excel file format support (.xlsx, .xls)
- [ ] Implement caching mechanisms for processed data
- [ ] Add batch processing capabilities
- [ ] Create CLI tool for command-line usage
- [ ] Add data transformation pipelines
- [ ] Implement async processing support
Version 1.2 (Future)
- [ ] Add database resource connectors (MySQL, PostgreSQL, SQLite)
- [ ] Implement API resource connectors (REST, GraphQL)
- [ ] Add data validation rule system
- [ ] Create visual data mapping interface
- [ ] Add support for nested data structures
- [ ] Implement data diff and merge capabilities
Long-term Goals
- [ ] Plugin system for third-party extensions
- [ ] Web-based data transformation UI
- [ ] Integration with popular frameworks (Laravel, Symfony)
- [ ] Performance optimization for big data processing
- [ ] Machine learning integration for data analysis# Data Reader
A flexible and robust PHP library for reading, processing, and outputting data from various sources with configurable transformation pipelines, validation, and multiple output formats.
Features
- Multiple Data Sources: Support for files (CSV, JSON, XML), arrays, and extensible resource types
- Configurable Processing: Transform and validate data during reading with custom configuration classes
- Multiple Output Formats: JSON, XML, CSV output with customizable options
- Robust Error Handling: Custom exceptions and comprehensive validation
- Clean Architecture: Interface-driven design following SOLID principles
- Type Safety: Full PHP 7.4+ type hints and strict typing
- Easy Integration: Simple fluent API for chaining operations
- Factory Methods: Quick setup for common use cases
- Field Mapping & Validation: Built-in support for data transformation and validation
Installation
Install via Composer:
Quick Start
Architecture
Core Components
Reader
The main orchestrator class that coordinates resource reading, data configuration, and output formatting.
Resources
Data sources that implement ResourceInterface:
- File: Read from files with multiple format handlers (CSV, JSON, XML)
- ArrayData: Process in-memory arrays with full configuration support
- Custom: Extend
Resourceclass for databases, APIs, or other sources
File Formats
Built-in support for multiple file formats:
- CSV: Comma-separated values with configurable delimiters
- JSON: JavaScript Object Notation with error handling
- XML: Extensible Markup Language with customizable element mapping
Configurations
Transform and validate data using ConfigInterface or extend BaseConfig:
Output Formats
Multiple output formats with customizable options:
- Json: JSON with formatting options
- XML: XML with custom root and item elements
- CSV: CSV with configurable delimiters and enclosures
Usage Examples
Quick Start with Factory Methods
Reading Different File Formats
CSV Files
JSON Files
XML Files
Processing Array Data
Multiple Output Formats
XML Output
CSV Output
Extending the Library
Custom Resource Types
Custom File Formats
Custom Output Formats
API Reference
Reader Class
Constructor: __construct(?ResourceInterface $resource = null, ?OutputInterface $output = null, ?ConfigInterface $config = null)
Methods:
resource(ResourceInterface $resource): self- Set data sourceconfig(ConfigInterface $config): self- Set data configurationoutput(OutputInterface $output): self- Set output formatrun(): mixed- Execute the data processing pipelinegetItems(): array- Get processed items without output formattinggetTotalItems(): int- Get count of processed items
Factory Class
ReaderFactory Methods:
createCsvReader(string $filename): Reader- Quick CSV reader setupcreateJsonReader(string $filename): Reader- Quick JSON reader setupcreateArrayReader(array $data): Reader- Quick array reader setup
Core Interfaces
DataReaderInterface
getItems(): arraygetTotalItems(): int
ResourceInterface
apply(ConfigInterface $config): array
ConfigInterface
configureItem($item): mixed- Transform individual data itemsconfigureFirstItem($item): mixed- Handle first item (headers, etc.)
OutputInterface
items($items): mixed- Format processed data for output
FileInterface
read($handle, ConfigInterface $config): array- Read from file handle
Built-in Classes
Resources
File(string $filename, FileInterface $format)- File-based data sourceArrayData(array $data = [])- Array-based data source
File Formats
CSV()- CSV file readerJSON()- JSON file readerXML(string $itemTag = 'item')- XML file reader
Output Formats
Json(int $options = JSON_PRETTY_PRINT)- JSON outputXML(string $root = 'data', string $item = 'item')- XML outputCSV(string $delimiter = ',', string $enclosure = '"')- CSV output
Configuration Base Classes
BaseConfig- Abstract base with field mapping and validationsetFieldMapping(array $mapping): selfaddValidator(callable $validator): selfmapFields($item): array(protected)validateItem($item): bool(protected)
Exception Classes
DataReaderException- Base exception classResourceException- Resource-related errorsConfigurationException- Configuration errorsOutputException- Output formatting errors
Requirements
- PHP 8.0 or higher (uses strict typing and return type declarations)
- No external dependencies for core functionality
- Optional dependencies for extended functionality:
phpoffice/phpspreadsheet- for Excel file supportext-simplexml- for XML processing (usually included)ext-json- for JSON processing (usually included)
Error Handling
The library provides comprehensive error handling with custom exception types:
Performance Considerations
Memory Usage
- Large Files: Consider implementing streaming for files > 100MB
- Array Processing: ArrayData loads all data into memory
- Output Buffering: JSON and XML outputs build complete strings in memory
Optimization Tips
License
This project is licensed under the MIT License - see the LICENSE file for details.
Roadmap
- [ ] Complete ArrayData implementation
- [ ] Add XML output format
- [ ] Implement data validation features
- [ ] Add streaming support for large files
- [ ] Create additional file format handlers (JSON, XML, Excel)
- [ ] Add caching mechanisms
- [ ] Implement batch processing capabilities
Support
For support, please open an issue on the GitHub repository.
All versions of data-reader with dependencies
ext-simplexml Version *