Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Object Mapper

Object Mapper Laravel Package

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.

View on GitHub
Deep Wiki
Context7

The Symfony Object Mapper component maps data between objects (e.g., DTOs, entities, API models) with minimal boilerplate. It streamlines transformations by leveraging PHP attributes to describe how properties should be copied or converted, keeping mapping logic explicit and maintainable.

Use it to centralize and standardize object-to-object mapping across your application while staying aligned with Symfony best practices.

  • Attribute-driven mapping configuration for clear, declarative rules
  • Maps between different class shapes (DTO ↔ entity, input ↔ domain)
  • Supports custom transformations and value conversion hooks
  • Integrates cleanly within the Symfony ecosystem and conventions
  • Encourages reusable, testable mapping logic
Frequently asked questions about Object Mapper
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport