PHPackages                             ideneal/request-content-converter-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ideneal/request-content-converter-bundle

ActiveSymfony-bundle

ideneal/request-content-converter-bundle
========================================

This bundle provides a way to convert and validate the request content specifying a format

v1.1.0(5y ago)6531MITPHPPHP &gt;=7.1.3CI failing

Since Jun 3Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Ideneal/IdenealRequestContentConverterBundle)[ Packagist](https://packagist.org/packages/ideneal/request-content-converter-bundle)[ RSS](/packages/ideneal-request-content-converter-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (12)Versions (4)Used By (0)

IdenealRequestContentConverterBundle
====================================

[](#idenealrequestcontentconverterbundle)

[![Packagist](https://camo.githubusercontent.com/6f94e34a851fff24bccb815276a26e9a2cfe63efc9f016aff382c18506e3ca05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6964656e65616c2f726571756573742d636f6e74656e742d636f6e7665727465722d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ideneal/request-content-converter-bundle)[![GitHub license](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](https://raw.githubusercontent.com/Ideneal/IdenealRequestContentConverterBundle/master/LICENSE)[![Travis branch](https://camo.githubusercontent.com/2b0f456abcdba1681903f64f8e1e52e6b6f58a48d3aebe4ae9b15ee82709e8a2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4964656e65616c2f4964656e65616c52657175657374436f6e74656e74436f6e76657274657242756e646c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Ideneal/IdenealRequestContentConverterBundle)[![Codacy branch](https://camo.githubusercontent.com/a672a8c69be03502fa0a55facba3f4bf437d1583af7aeee3b9ec0f85fe06164a/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f66643261656563343961623534626134393630616430343335326565326365322f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://www.codacy.com/app/ideneal-ztl/IdenealRequestContentConverterBundle)

This is a Symfony bundle that extends the features of [SensioFrameworkExtraBundle](https://github.com/sensiolabs/SensioFrameworkExtraBundle). It provides a way to deserialize and validate the request content into a specified class or entity.

Installation
------------

[](#installation)

Add the bundle to your `composer.json` file:

```
composer require ideneal/request-content-converter-bundle
```

Usage
-----

[](#usage)

### ContentParamConverter

[](#contentparamconverter)

The ContentParamConverter permits you to convert the request content into a specific controller action parameter.

Let's see a simple use case where you want to subscribe a lead. Create a simple Lead class:

```
namespace App\Inputs;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;

class Lead
{
    /**
     * @Assert\Type("string")
     * @Assert\NotBlank
     */
    private $name;

    /**
     * @Assert\Email(groups={"strict"})
     * @Groups("registration")
     */
    private $email;

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }

    public function getEmail()
    {
        return $this->email;
    }
}
```

Inside the controller create a simple action and add the `ContentParamConverter` annotation specifying the request format:

```
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Ideneal\Bundle\RequestContentConverterBundle\Configuration\ContentParamConverter;
use App\Inputs\Lead;

class SubscribeController extends AbstractController
{
    /**
     * @Route("/subscribe", name="subscribe")
     * @ContentParamConverter("lead", methods={"POST"}, format="json")
     */
    public function subscribe(Lead $lead)
    {
        /* Do some operations .... */

        dump($lead);
        return new JsonResponse(['message' => 'ok']);
    }
}
```

In this case the annotation ContentParamConverter automatically maps the request content json keys into related Lead properties and validate it.

You could also use as well `Json` and `Xml` without set the format instead of ContentParamConverter.

### EntityContentParamConverter

[](#entitycontentparamconverter)

In order to map the request content to a Doctrine entity you could use EntityContentParamConverter. You could also use `JsonEntity` and `XmlEntity` where the format has been specified.

Let's see a use case where you have to update a product in db. So you have an entity *Product*.

```
namespace App\Entity;

use App\Repository\ProductRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass=ProductRepository::class)
 */
class Product
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @Assert\Length(min=3)
     */
    private $name;

    /**
     * @ORM\Column(type="integer")
     * @Assert\Positive
     */
    private $price;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getPrice(): ?int
    {
        return $this->price;
    }

    public function setPrice(int $price): self
    {
        $this->price = $price;

        return $this;
    }
}
```

In order to update a specific Product you could create the following action:

```
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Ideneal\Bundle\RequestContentConverterBundle\Configuration\JsonEntity;
use App\Entity\Product;

class ApiController extends AbstractController
{
    /**
     * @Route("/api/products/{id}", name="update_product", methods={"PUT"})
     * @JsonEntity("product", class="App\Entity\Product")
     */
    public function update(Product $product)
    {
        /* Do some operations... */

        dump($product);
        $em = $this->getDoctrine()->getManager();
        $em->flush();

        return new JsonResponse(['message' => 'ok']);
    }
}
```

Within controller action the `$product` has just been updated and validated by the json request.

Annotation Options
------------------

[](#annotation-options)

In addiction to `format` parameter you could set other options.

### groups

[](#groups)

Sometimes, you want to deserialize different sets of attributes from your selected class. Groups are a handy way to achieve this need.

The value of the groups key can be a single string, or an array of strings.

### validate

[](#validate)

Default is *true*. If *false* the validation will be disabled.

### validation\_groups

[](#validation_groups)

By default, all constraints of selected class will be checked whether or not they actually pass. In some cases, however, you will need to validate an object against only some constraints on that class. To do this, you can organize each constraint into one or more "validation groups" and then apply validation against just one group of constraints.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~240 days

Total

2

Last Release

1925d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4932b6ca6ef102099284dc463673b659b109f1a50bfca5f0efd2c826529e0991?d=identicon)[Ideneal](/maintainers/Ideneal)

---

Top Contributors

[![Ideneal](https://avatars.githubusercontent.com/u/183482?v=4)](https://github.com/Ideneal "Ideneal (22 commits)")

---

Tags

requestformatcontentdeserialization

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ideneal-request-content-converter-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/ideneal-request-content-converter-bundle/health.svg)](https://phpackages.com/packages/ideneal-request-content-converter-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M191](/packages/simplesamlphp-simplesamlphp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
