symfony/object-mapper
Symfony Object Mapper maps data between objects (e.g., DTOs to entities) using PHP attributes to define field mappings. It reduces boilerplate transformation code, supports configurable mapping logic, and integrates cleanly with Symfony applications.
[Map] attributes) and layered architecture (e.g., DTO ↔ Entity transformations).Attribute, PropertyAccess), introducing vendor lock-in.UserEntity → UserDTO with nested AddressDTO using [Map] attributes.CreateUserCommand → UserAggregate with conditional logic.Attribute class) or composer scripts to bypass dependencies.PropertyAccess may clash with Laravel’s illuminate/support.| Risk Area | Symfony Risk Level | Laravel Risk Level | Mitigation Strategy |
|---|---|---|---|
| Vendor Lock-in | High | Critical | Avoid in Laravel; use Spatie DTOs instead. |
| PHP Version | Low (8.4+) | High (blocker) | Upgrade PHP if Symfony-bound; else skip. |
| Dependency Bloat | Medium | High | Evaluate Symfony’s symfony/property-access impact. |
| Community Support | Medium (Symfony) | None (Laravel) | Rely on Symfony docs; no Laravel-specific help. |
| Long-Term Viability | Medium | Critical | Zero Laravel adopters; prefer framework-native tools. |
| Attribute Overhead | Low | High | Laravel lacks native attribute support; requires extra config. |
| Performance | Low | Medium | Benchmark vs. Spatie DTOs/Fractal. |
Symfony Projects:
Laravel Projects:
Cross-Cutting:
Attribute requires PHP 8.4+ tooling)?league/glide, matthecatlab/uml) that avoid Symfony dependencies?| Component | Symfony Fit | Laravel Fit | Notes |
|---|---|---|---|
| Dependency Injection | Native (Symfony DI) | Broken (Symfony DI conflicts) | Requires custom binding in Laravel. |
| Attribute Support | Native (PHP 8.0+) | Limited (PHP 8.0+ but no Laravel integration) | Laravel lacks attribute tooling. |
| PHP Version | 8.4+ | Blocker (8.1–8.3 common) | Upgrade required for Laravel. |
| Messenger Component | Seamless (commands/queries) | N/A | Not applicable to Laravel. |
| API Platform | Native (DTOs, serialization) | N/A | Symfony-only feature. |
| Doctrine ORM | Works (entity ↔ DTO) | Works (but Symfony dependency) | Overkill for Laravel’s Eloquent. |
| Testing | PHPUnit/Bridge integration | Manual setup | No Laravel-specific test utilities. |
Attribute system.composer.json:
"require": {
"symfony/object-mapper": "^8.0"
}
services.yaml (if not auto-discovered):
Symfony\Component\ObjectMapper\ObjectMapper:
arguments:
- ['@property_access']
#[Map]):
#[Map(target: UserDTO::class)]
class UserEntity { ... }
ObjectMapper into services:
public function __construct(private ObjectMapper $mapper) {}
$dto = $mapper->map($entity);
ObjectMapperTestCase or custom assertions.Attribute and PropertyAccess (complex, unsupported).# composer.json
"extra": {
"laravel": {
"dont-discover": ["Symfony\\Component\\ObjectMapper\\*"]
}
}
// Manual shim (not advised)
$mapper = new \Symfony\Component\ObjectMapper\ObjectMapper(
new \Symfony\Component\PropertyAccess\PropertyAccess()
);
PropertyAccess may conflict with Laravel’s illuminate/support.| Feature | Symfony Compatibility | Laravel Compatibility | Notes |
|---|---|---|---|
| Attribute-based mapping | ✅ Native | ❌ No support | Laravel lacks attribute tooling. |
| Nested object mapping | ✅ Supported | ❌ No built-in | Requires custom logic in Laravel. |
| Conditional mapping | ✅ Supported | ❌ No built-in | Use Spatie DTOs’ mapUsing instead. |
| Collection transforms | ✅ Supported | ❌ No built-in | Use Laravel Collections + custom logic. |
| **Constructor arguments |
How can I help you explore Laravel packages today?