weblabel/data-transformer-bundle
A Symfony bundle for transforming and normalizing data between formats. It offers reusable, extensible transformers to keep mapping logic clean and decoupled from your application code, simplifying DTO conversion, API payload handling, and consistent data presentation.
composer require weblabel/data-transformer-bundle weblabel/data-transformer
config/bundles.php:
Weblabel\DataTransformerBundle\WeblabelDataTransformerBundle::class => ['all' => true],
vendor/weblabel/data-transformer-bundle/src/DependencyInjection/ for the extension (what config keys exist, which tags get registered) and Resources/config/ for the service definitions. The README of the underlying weblabel/data-transformer package is where the real API lives — the bundle is just a Symfony glue layer.public function __construct(private DataTransformerInterface $transformer) {}
public function __invoke(array $payload): MyDto {
return $this->transformer->transform($payload, MyDto::class);
}
weblabel.data_transformer.transformer — verify the exact tag in the bundle's CompilerPass), and let the registry collect it. Autoconfigure this tag in config/services.yaml so new transformers "just work".transform($input): mixed and sometimes reverse(...). Keep each transformer small and single-purpose (e.g. AddressTransformer, MoneyTransformer) rather than one giant mapper — it makes caching and unit testing trivial.supports(), use that to build per-field pipelines:
App\Transformer\AddressTransformer:
tags: [{ name: 'weblabel.data_transformer.transformer', priority: 10 }]
Serializer/ObjectNormalizer attributes (#[SerializedName], #[Groups]) for leaf nodes rather than re-implementing normalization.static helper calls sprinkled across controllers and become injectable, mockable collaborators.Form\DataTransformerInterface; they share a name but not a contract.composer why-not weblabel/data-transformer-bundle after upgrading Symfony; you may need to add symfony/deprecation-contracts and patch getContainerExtension() signatures, or fork it.services.yaml doesn't match what the bundle's compiler pass collects. Debug with php bin/console debug:container --tag=<tag> — if your service isn't listed, the tag name or autoconfigure rule is wrong.Configuration class; misspelled keys in config/packages/weblabel_data_transformer.yaml throw at cache warmup. Start with an empty config block and let validation errors show you the valid keys.vendor/weblabel/data-transformer/, not the bundle. Read that package's source and tests; the bundle source is small enough to read in one sitting.mixed will happily swallow strings where you expected arrays (or vice versa). Add a supports() guard or an assertion at the boundary, and give each transformer a unit test with the exact shape of input you receive from Symfony (Request query params are strings, Messenger payloads are arrays, entity getters return objects).Weblabel\DataTransformerBundle\ is a foot-gun.symfony/serializer + symfony/property-info + explicit DTOs gives you the same "transform data cleanly" outcome with an actively maintained dependency. Reach for this bundle only if you're already committed to the weblabel/data-transformer API.How can I help you explore Laravel packages today?