symfony/object-mapper
Symfony Object Mapper component maps data from one object to another using PHP attributes. Simplifies DTO/entity transformations, supports configurable mapping rules, and integrates with the Symfony ecosystem. Documentation and contributions are handled in the main Symfony repository.
UserEntity to UserResponseDTO with zero boilerplate.array_map or create() chains in controllers with attribute-driven mapping (e.g., @MapEntity, @Ignore).User tables to UserProfile DTOs).UserFactory → User).OrderCreatedEvent → OrderCommand).Adopt if:
string → Carbon).setName() chains in controllers).@MapEntity, @Ignore) to reduce boilerplate.Look elsewhere if:
Model::find() → json_encode()).spatie/laravel-data or php-http/message for tighter integration.symfony/serializer instead).For Executives:
"This package slashes API development time by automating the tedious task of manually mapping between database records, internal objects, and API responses. For example, converting a UserEntity to a UserResponseDTO—which today requires 20+ lines of boilerplate—could be done in 2 lines with attributes like @MapEntity. This directly supports our goals to [reduce tech debt/accelerate feature delivery] while keeping code clean and maintainable. It’s a low-risk choice, backed by Symfony’s stability, and MIT-licensed for full flexibility. The ROI comes from faster iterations and reduced bugs in our API layer."
For Engineers:
"Symfony’s Object Mapper lets us replace repetitive mapping logic with declarative attributes (e.g., @MapEntity, @Ignore), cutting cognitive load and runtime errors. It integrates well with Laravel’s DI system (via symfony/dependency-injection) and supports nested objects/collections out of the box. For teams using Symfony components or PHP 8+, this is a no-brainer—it’s battle-tested, actively maintained, and avoids reinventing the wheel. If we’re not using Symfony, we could evaluate alternatives like spatie/laravel-data, but this gives us the most ‘batteries-included’ experience for complex mappings. It’s especially useful for APIs, DDD, or legacy integrations where object transformation is a pain point."
For Architects: *"This package aligns with clean architecture principles by enforcing separation between domain models and API contracts. It’s particularly valuable for:
How can I help you explore Laravel packages today?