- Can I use Symfony Object Mapper in Laravel without Symfony’s full stack?
- No, this package requires Symfony components like `symfony/attribute` and `symfony/property-access`, which introduce dependency conflicts with Laravel’s `illuminate/support`. Even with PHP 8.4+, you’d need manual shimming or polyfills, making it impractical for most Laravel projects.
- What’s the minimum PHP version required for Symfony Object Mapper?
- PHP 8.4+. Laravel projects often use PHP 8.1–8.3, so upgrading just for this package may not be worth the effort unless you’re already committed to Symfony 8.4+. Check your Laravel version’s supported PHP range first.
- How does Symfony Object Mapper compare to Spatie’s DTO package for Laravel?
- Spatie’s DTO package is lightweight, Laravel-native, and avoids Symfony dependencies entirely. It handles basic mapping without attributes, while Symfony’s mapper adds complexity (attributes, Symfony DI) that Laravel doesn’t need. Spatie is the clear winner for Laravel.
- Does Symfony Object Mapper support nested object mapping (e.g., DTOs inside DTOs)?
- Yes, it supports nested mappings via attributes like `[Map]` and custom logic. However, in Laravel, you’d still face Symfony dependency issues, and alternatives like Fractal or custom mappers can achieve the same without vendor lock-in.
- Will Symfony Object Mapper work with Laravel’s Eloquent models?
- Technically, it could map Eloquent models to DTOs, but the Symfony dependency (`symfony/property-access`) may conflict with Laravel’s `illuminate/support`. The overhead isn’t justified—Laravel’s native casting or Spatie’s DTOs are simpler solutions.
- Can I use Symfony Object Mapper for API request/response transformations?
- Yes, but only in Symfony apps. For Laravel, Fractal or Laravel’s built-in JSON responses are better choices. Symfony’s mapper adds unnecessary complexity (attributes, Symfony DI) that Laravel APIs don’t require.
- How do I configure custom value transformations in Symfony Object Mapper?
- Use the `@Map` attribute with `type: 'method'` or `type: 'service'` to define custom logic. However, in Laravel, you’d need to manually register Symfony services in Laravel’s container, which is error-prone and not recommended.
- Does Symfony Object Mapper integrate with Laravel’s service container?
- No, it’s designed for Symfony’s DI container. Laravel’s container uses a different structure, and binding Symfony services would require custom bootstrapping—far more work than using Laravel-native tools like Spatie’s DTOs.
- What are the performance implications of using Symfony Object Mapper in Laravel?
- Symfony’s mapper relies on reflection and attributes, which can bloat autoloading and runtime performance. Laravel’s native solutions (e.g., Spatie DTOs) are optimized for PHP’s lower-level operations and avoid Symfony’s overhead.
- Are there Laravel-compatible alternatives to Symfony Object Mapper?
- Yes: **Spatie’s DTO package** (lightweight, no dependencies), **Fractal** (API serialization), or **custom mappers** (for full control). These avoid Symfony’s lock-in and work seamlessly with Laravel’s architecture.