Download the PHP package guennichi/mapper without Composer
On this page you can find all versions of the php package guennichi/mapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download guennichi/mapper
More information about guennichi/mapper
Files in guennichi/mapper
Package mapper
Short Description A lightweight library to map array data to PHP immutable objects
License MIT
Informations about the package mapper
Mapper: Map arrays into PHP objects and collections
A lightweight, high-performance PHP library that maps array data into immutable objects, collections, and strongly typed arrays via constructors. Perfect for transforming API responses, JSON data, or any array structure into type-safe PHP objects.
Why Use Mapper?
- 🚀 Fast: Up to 7x faster than Symfony Serializer (see benchmarks below)
- 🔒 Type-safe: Leverages PHP 8.1+ type system and PHPDoc annotations
- 📦 Immutable: Works with readonly properties for immutable objects
- 🎯 Simple: Map arrays to objects using constructor parameters - no setters needed
- ⚡ Production-ready: Built-in caching for optimal performance
Benchmark
| Benchmark | Revs | Its | mem_peak | Mode | rstdev |
|---|---|---|---|---|---|
unserialize() |
5000 | 5 | 1.724mb | 9.547μs | ±1.51% |
symfony/serializer |
5000 | 5 | 3.489mb | 122.343μs | ±0.84% |
guennichi/mapper |
5000 | 5 | 2.972mb | 16.638μs | ±0.41% |
Check benchmark/ directory for more details about the implementation.
Installation
Requirements: PHP ^8.1
Quick Start
Real-World Example: API Response Mapping
Transform API responses into strongly-typed objects:
See docs/USAGE.md for complete examples with nested objects, collections, and more.
Migration from serialize() / unserialize()
Before:
After:
Benefits: Type-safe, works with immutable objects, safe with untrusted data, human-readable JSON.
See docs/USAGE.md for detailed migration guide.
Features
- ✅ Map arrays to objects via constructors
- ✅ Support for collections, nested objects, enums, DateTime
- ✅ Custom attributes for field mapping, type coercion, date formats
- ✅ Built-in caching for production performance
- ✅ Full type validation and error handling
Documentation
📖 Complete Usage Guide - Comprehensive documentation covering:
- Configuration & setup (development and production)
- Collections and nested objects
- Complete type system reference
- All attributes with examples
- Performance optimization
- Error handling and troubleshooting
- Best practices
License
MIT
Credits
Special thanks to @Gabriel Ostrolucký for his support and advice to make this happen.
All versions of mapper with dependencies
phpdocumentor/reflection-docblock Version ^5.3
phpdocumentor/type-resolver Version ^1.6
symfony/filesystem Version >=5.4