PHPackages                             n7/symfony-http-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. n7/symfony-http-bundle

ActiveSymfony-bundle

n7/symfony-http-bundle
======================

v2.0.1(10mo ago)3201.2k↓32.9%4MITPHPPHP ^8.0

Since Jan 31Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/nope7777/symfony-http-bundle)[ Packagist](https://packagist.org/packages/n7/symfony-http-bundle)[ RSS](/packages/n7-symfony-http-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (31)Used By (0)

About
=====

[](#about)

This bundle allows you to describe requests as classes and inject them into the controller. If a request fails validation, an exception with validation errors will be thrown, which can be handled and the response returned in the required format. If the request is valid, you will have an object with a well-described structure in the controller, all that remains is to process the request.

Handling validation errors
--------------------------

[](#handling-validation-errors)

Bundle comes with a listener that converts validation errors into a response, you can use it as an example to handle errors in the format you need. To use it, add the following lines to your `config/services.yaml`:

```
# (config/services.yaml)

services:
    # ...

    N7\SymfonyHttpBundle\EventListener\RequestPayloadExceptionListener:
        tags:
            - { name: kernel.event_listener, event: kernel.exception }

```

This listener will return validation errors in the following json format (example):

```
{
  "code": 422,
  "message": "Validation error occurred",
  "errors": {
    "[username]": "This field is missing.",
    "[age]": "This field is missing.",
    "[terms]": "This field is missing."
  }
}
```

Requests injection
------------------

[](#requests-injection)

*HTTP requests query parameters always come as strings, to validate them correctly, they are soft casted according to type annotations in request class.*

Request class:

```
use N7\SymfonyHttpBundle\Interfaces\RequestPayloadInterface;

final class CreateUserRequest implements RequestPayloadInterface
{
    #[Constraints\NotBlank]
    #[Constraints\Type('string')]
    private string $username;

    #[Constraints\NotBlank]
    #[Constraints\Type('integer')]
    private int $age;

    #[Constraints\NotBlank]
    #[Constraints\Type('boolean')]
    private bool $terms;
}
```

Controller action:

```
#[Route('/api/endpoint')]
public function create(CreateUserRequest $request): Response
{
    dd($request);
}
```

Response for request without parameters:

```
{
  "code": 422,
  "message": "Validation error occurred",
  "errors": {
    "[username]": "This field is missing.",
    "[age]": "This field is missing.",
    "[terms]": "This field is missing."
  }
}
```

If request class implements the `RequestPayloadInterface`, the request type will be determined automatically (get/form-data/json). If you want to specify exactly what type of request to use, then you can implement one of these interfaces:

- `RequestQueryParametersInterface` - query parameters (GET request)
- `RequestFormDataInterface` - form data (POST/PUT/... requests)
- `RequestJsonPayloadInterface` - json (POST/PUT/... requests)

Mutators
--------

[](#mutators)

In case you need to transform the field value before validation, you can make a custom mutator (example):

```
use N7\SymfonyHttpBundle\Annotations\ValueMutatorInterface;

#[\Attribute]
class StringLimitMutator implements ValueMutatorInterface
{
    public function mutate($value, array $payload, string $property)
    {
        if (! is_string($value)) {
            return $value;
        }

        return mb_substr($value, 0, 50);
    }
}

final class TestRequest implements RequestPayloadInterface
{
    #[Constraints\NotBlank]
    #[Constraints\Type('string')]
    #[StringLimitMutator]
    private string $address;
}
```

Nested objects and array of objects
-----------------------------------

[](#nested-objects-and-array-of-objects)

The example below shows how to work with nested objects and arrays of nested objects:

```
use JMS\Serializer\Annotation as Serializer;

final class Request implements RequestPayloadInterface
{
    #[Constraints\NotBlank]
    #[NestedObject(NestedObject::class)]
    private NestedObject $select2;

    #[Constraints\NotBlank]
    #[NestedObjects(NestedObject::class)]
    #[Serializer\Type("array")]
    private array $list;
}
```

Arrays
------

[](#arrays)

arrays of integer/float/bool must have `@var` annotation describing their inner elements scalar type. It needed for soft type casting before validation. Available values: `int[]`, `float[]`, `boolean[]`, `string[]`.

Example:

```
final class Request implements RequestPayloadInterface
{
    /**
     * @var float[]
     */
    #[Constraints\NotBlank]
    #[Serializer\Type("array")]
    private array $amounts;
}
```

AllowExtraFields and AllowMissingFields
---------------------------------------

[](#allowextrafields-and-allowmissingfields)

Validatior `allowExtraFields` and `allowMissingFields` parameters can be overwritten with annotations:

```
use N7\SymfonyValidatorsBundle\Options\AllowExtraFields;
use N7\SymfonyValidatorsBundle\Options\AllowMissingFields;

#[AllowExtraFields]
#[AllowMissingFields]
final class Request implements RequestPayloadInterface
{

}
```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance53

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 87.1% 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 ~59 days

Recently: every ~92 days

Total

28

Last Release

326d ago

Major Versions

v1.0.25 → v2.02024-11-24

PHP version history (4 changes)v1.0.0PHP ^7.0

v1.0.9PHP ^7.4

v1.0.10PHP ^7.4|^8.0

v2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/97680b0ee6c90c373cf3d31e4d230601a2847ace93229dc0eb1f4081ca0b7ff2?d=identicon)[n7](/maintainers/n7)

---

Top Contributors

[![nope7777](https://avatars.githubusercontent.com/u/8977306?v=4)](https://github.com/nope7777 "nope7777 (27 commits)")[![Vladislavs-Ko](https://avatars.githubusercontent.com/u/128796796?v=4)](https://github.com/Vladislavs-Ko "Vladislavs-Ko (2 commits)")[![jimmwo](https://avatars.githubusercontent.com/u/7640716?v=4)](https://github.com/jimmwo "jimmwo (1 commits)")[![Zuken](https://avatars.githubusercontent.com/u/3996877?v=4)](https://github.com/Zuken "Zuken (1 commits)")

### Embed Badge

![Health badge](/badges/n7-symfony-http-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/n7-symfony-http-bundle/health.svg)](https://phpackages.com/packages/n7-symfony-http-bundle)
```

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[sulu/sulu

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

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

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[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)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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