boshurik/mapper
Lightweight Laravel/PHP object mapper for converting between arrays and DTOs/entities. Helps map input data to typed objects and back with minimal boilerplate, supporting custom mapping rules and nested structures for clean data transformations.
array_map, stdClass, or custom mappers) or frameworks like Symfony Serializer or Laravel’s built-in casting.spatie/array-to-object, vinkla/hashids) already covers needs.DTO → Entity → DTO).spatie/laravel-data (for immutable DTOs).illuminate/support/Str or array_map (for simple cases).fillable fields)?league/glide, jenssegers/date)?symfony/serializer instead).$this->app->bind(MapperInterface::class, function ($app) {
return new Mapper(); // Assuming default constructor
});
- Extend the mapper to **auto-detect Eloquent models** via traits or interfaces.
class UserMapper extends Mapper {
public function mapToUser(array $data): User { ... }
}
ReflectionClass deprecations).Facade dependencies).PropertyAccess).array_map in controllers).composer require boshurik/mapper
null values, unsupported types).array_map calls.collect()) for simple cases.memory_get_usage()).Illuminate\Support\Facades\Cache) could help.Model::hydrate()), test with large datasets.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package incompatibility | Breaks mapping in production | Fork and patch, or switch to alternative |
| Undefined property mapping | Silent failures or corrupt data | Add validation layers (e.g., Validator) |
| PHP 8.x deprecation warnings | Runtime errors | Polyfill or migrate to active package |
| Circular reference loops | Infinite recursion, crashes | Configure max depth or use ignoreMissing |
| Missing documentation | Onboarding delays | Create internal runbook |
Mapper::map($source, $destination)).How can I help you explore Laravel packages today?