Download the PHP package gbelsalvador/data-transformer without Composer
On this page you can find all versions of the php package gbelsalvador/data-transformer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gbelsalvador/data-transformer
More information about gbelsalvador/data-transformer
Files in gbelsalvador/data-transformer
Package data-transformer
Short Description Professional PHP library for transforming data between multiple formats
License MIT
Informations about the package data-transformer
Data Transformer
gbelsalvador/data-transformer is a PHP library for reading, transforming, validating, and exporting structured data across multiple formats.
It is designed for practical data workflows:
- import from
CSV,JSON,XML,SQL, orXLSX - normalize data into a consistent PHP array structure
- filter, map, and validate rows through a fluent pipeline
- export the result to another format
The project aims to offer a clean developer experience, predictable behavior, and a solid base for production-oriented data conversion workflows.
Documentation
- French README:
README.fr.md - HTML documentation:
docs/index.html
Why This Library
Most conversion utilities stop at file-to-file export. Data Transformer goes further by adding a transformation pipeline between the reader and writer.
That means you can:
- convert formats
- rename and reshape fields
- filter rows
- validate data before export
- get an execution report with counts and validation errors
Features
- Multi-format support:
CSV,JSON,XML,SQL,XLSX - Fluent transformation pipeline with
read(),filter(),map(),validate(),write() - Structured SQL filters for safer queries
- Execution reporting via
ExecutionResult - Spreadsheet export hardening for CSV/XLSX formula injection
- XML parsing hardened with
LIBXML_NONET - PHPUnit test suite for pipeline behavior and file integrations
- PSR-4 autoloading and PSR-12-friendly code style
Installation
Requirements
- PHP
>= 8.0 phpoffice/phpspreadsheet^5.4
Supported Formats
| Format | Read | Write |
|---|---|---|
| CSV | Yes | Yes |
| JSON | Yes | Yes |
| XML | Yes | Yes |
| SQL | Yes | Yes |
| XLSX | Yes | Yes |
Quick Start
Fluent Pipeline
The fluent API is the recommended approach for non-trivial workflows.
Core Concepts
Readers
Readers load data from a source and return a normalized PHP array:
Available readers:
CsvReaderJsonReaderXmlReaderSqlReaderXlsxReader
Writers
Writers receive normalized rows and persist them to a target format.
Available writers:
CsvWriterJsonWriterXmlWriterSqlWriterXlsxWriter
ExecutionResult
Every completed transformation returns an ExecutionResult object with runtime information:
rowsRead()rowsWritten()rowsFilteredOut()rowsInvalid()errorCount()duration()validationErrors()
Usage Examples
CSV to JSON
SQL to XLSX
JSON to XML
Validation Rules
The current validation layer supports:
requiredemailnumericintegerbooleandatemax:<length>in:value1,value2,value3same:other_field
Example:
SQL Safety
SqlReader supports two approaches:
filterswhereClause+whereParams
The recommended approach is filters, because it builds parameterized conditions from a structured array.
Supported structured operators:
=!=>>=<<=likeinis_nullis_not_null
Security Notes
The library includes several basic hardening measures:
- SQL identifiers are validated before query construction
- CSV and XLSX exports neutralize formula-like values
- XML reading uses
LIBXML_NONETto reduce external entity/network risks
These protections help reduce common issues, but you should still treat file paths, SQL configuration, and user-provided inputs as untrusted data in your application layer.
API Overview
Transformer
Reader Signatures
Writer Signatures
Testing
Install development dependencies:
Run the test suite:
Current coverage includes:
- pipeline behavior
- validation behavior
- CSV/JSON/XML integration flows
- SQL reader/writer tests when
pdo_sqliteis available
Note: SQL integration tests are skipped automatically if the pdo_sqlite driver is not enabled in your PHP environment.
Project Structure
Roadmap
Planned improvements for upcoming versions:
- streaming for large datasets
- richer schema validation
- more transformation primitives
- append/merge output strategies
- additional input sources such as HTTP or YAML
Contributing
Contributions, bug reports, and improvement ideas are welcome.
If you want to contribute:
- Fork the repository
- Create a feature branch
- Add or update tests
- Open a pull request with a clear description
License
This project is released under the MIT License.