Search by

netmex / hydrator-bundle

Zany101

Package info

github.com/netmexmedia/HydratorBundle

Type:symfony-bundle

pkg:composer/netmex/hydrator-bundle

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2.0.0 2026-10-14 09:57 UTC

README

Netmex HydratorBundle is a Symfony bundle for mapping, transforming, and validating input data into PHP objects and data transfer objects (DTOs).

Define reusable mapper definitions to control how input fields are processed, how values are transformed, and how validation constraints are applied. The bundle also supports nested mappings, recursive hydration, and mapping collections of input data.

Features

  • Reusable mapper definitions
  • Custom field transformers
  • Symfony Validator constraints
  • Nested and recursive hydration
  • Collection hydration
  • Hydration of existing objects
  • Configurable mapping options
  • Integration with Symfony's service container

Installation

composer require netmex/hydrator-bundle

See the installation guide for configuration details.

Quick start

Create a mapper definition by implementing MapperDefinitionInterface:

<?php

namespace App\Hydrator;

use App\Entity\User;
use Netmex\HydratorBundle\Contracts\BuilderInterface;
use Netmex\HydratorBundle\Contracts\MapperDefinitionInterface;
use Netmex\HydratorBundle\Resolver\OptionsResolver;

final class UserHydrator implements MapperDefinitionInterface
{
    public function process(BuilderInterface $builder): void
    {
        $builder
            ->add('name')
            ->add('email');
    }

    public function options(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'model' => User::class,
        ]);
    }
}

Inject MapperInterface into your service or controller and use build():

$user = $mapper->build(UserHydrator::class, $inputData);

The input data should be an associative array containing the fields expected by the mapper.

Documentation

Requirements

Check composer.json for the supported PHP and Symfony versions.

License

See the repository's LICENSE file.