49 Commits

Author SHA1 Message Date
Nicolas Grekas
47bc33d92b feature #52134 [HttpKernel] Add option to map empty data with MapQueryString and MapRequestPayload (Jeroeny)
This PR was merged into the 8.1 branch.

Discussion
----------

[HttpKernel] Add option to map empty data with `MapQueryString` and `MapRequestPayload`

| Q             | A
| ------------- | ---
| Branch?       | 8.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

When `#[MapQueryString]` or `#[MapRequestPayload]` is used on a nullable/default-valued parameter and the query string or request body is empty, the resolver short-circuits and returns `null` without ever calling the serializer. This prevents custom denormalizers from constructing the object.

This PR adds `bool $mapWhenEmpty = false` to both attributes. When `true`, the resolver passes `[]` to `denormalize()` even when no data is present, giving custom denormalizers a chance to populate the DTO.

```php
public function __construct(
    #[MapRequestPayload(mapWhenEmpty: true)] SearchFilters $filters,
) {}
```

**Use case:** a DTO where some fields come from the request and others are injected by a custom denormalizer (e.g. from the security context or session):

```php
class SearchFilters {
    public function __construct(
        public ?string $keyword = null,  // from query string
        public int $userId = 0,          // set by a custom denormalizer
    ) {}
}
```

Without `mapWhenEmpty`, an empty query string yields `null`, the denormalizer never runs. With `mapWhenEmpty: true`, denormalization proceeds and the custom denormalizer can populate `$userId`.

Commits
-------

5117bb6f178 [HttpKernel] Add argument `$mapWhenEmpty` to `MapQueryString` and `MapRequestPayload` for always attempting denormalization with empty query and request payload
2026-03-17 17:21:39 +01:00
Steven Renaux
b402f7bea9 [HttpKernel] Add #[MapRequestHeader] attribute and resolver 2026-03-09 16:09:42 +01:00
Jeroeny
453508663d [HttpKernel] Add argument $mapWhenEmpty to MapQueryString and MapRequestPayload for always attempting denormalization with empty query and request payload 2026-03-05 20:23:06 +01:00
Konstantin Myakshin
08698746ec Create #[Serialize] Attribute to serialize Controller Result 2026-02-13 08:51:08 +01:00
Nicolas Grekas
83a1ea547c [HttpKernel] Dispatch events named after controller attributes 2026-02-03 20:43:37 +01:00
Nicolas Grekas
44f9ba8939 feature #58273 Allow usage of expressions for defining validation groups in #[MapRequestPayload] (Brajk19)
This PR was merged into the 8.1 branch.

Discussion
----------

 Allow usage of expressions for defining validation groups in `#[MapRequestPayload]`

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| License       | MIT

This PR adds option to use Expression for defining validation groups when using `#[MapRequestPayload]` and
`#[MapQueryString]`

Inspired by expression options when using `#[IsGranted]`, request and args are available.

Example:
We have route which is used to update user info. Entity `User` has property `type` which can be `admin` or `regular`.
If user is admin, his password must be very strong and they must have image while regular user can have weaker password and image is not required.
Payload used in request:
```php
final readonly class UpdateUserDTO
{
    public function __construct(
        #[Assert\NotNull(message: 'Admin user must have image', groups: ['admin'])]
        public ?string $image,
        #[Assert\PasswordStrength(minScore: Assert\PasswordStrength::STRENGTH_MEDIUM, groups: ['regular'])]
        #[Assert\PasswordStrength(minScore: Assert\PasswordStrength::STRENGTH_VERY_STRONG, groups: ['admin'])]
        public string  $password,
    ) {
    }
}
```

We need to dynamically determine which validation group to use based on context (User that is being updated).
Current way of doing this is to manually call `validate` method:
```php
$violations = $this->validator->validate($dto, groups: [$user->getType()]);
// handle violations...
```

This PR allows usage of Expression with access to arguments so above code can be replaced with `#[MapRequestPayload]`
```php
#[Route('/user/{id}', methods: ['PUT'])]
public function updateUserAction(
    User $user,
    #[MapRequestPayload(
        validationGroups: [new Expression('args["user"].getType()')],
    )] UpdateUserDTO $dto
)
```

Commits
-------

61c92e545d4 [HttpKernel] Allow usage of expressions for defining validation groups in `#[MapRequestPayload]`
2026-02-03 08:20:02 +01:00
Adrian Brajkovic
0446ea6232 [HttpKernel] Allow usage of expressions for defining validation groups in #[MapRequestPayload] 2026-02-03 08:19:46 +01:00
valtzu
982e3b59f5 [Security][Cache] Add this to expression vars when available 2026-02-02 19:10:02 +02:00
Nicolas Grekas
f6ce44b345 [HttpKernel] Remove state from CacheAttributeListener 2026-01-14 14:25:33 +01:00
Nicolas Grekas
0f2de035b0 [HttpKernel] Optimize dealing with #[Cache] "if" condition 2026-01-14 14:02:30 +01:00
HypeMC
d15c54692d [HttpKernel] Allow setting a condition when #[Cache] should be applied 2026-01-06 16:40:35 +01:00
HypeMC
3c8429dc19 [HttpKernel] Allow using closures with the #[Cache] attribute 2026-01-06 12:49:53 +01:00
Christian Flothmann
4e1be73e62 drop the ability to configure a signer with the IsSignatureValid attribute 2025-09-15 14:33:55 +02:00
Santiago San Martin
e129d98639 [HttpKernel] Add #[IsSignatureValid] attribute 2025-09-14 10:10:19 +02:00
Nicolas Grekas
dc54eb349f [HttpKernel] Improve MapQueryParameter handling of options 2025-01-29 11:17:50 +01:00
Christian Flothmann
25193ed922 Merge branch '7.2' into 7.3
* 7.2: (37 commits)
  fix dumped markup
  improve amqp connection issues
  [Serializer] [ObjectNormalizer] Filter int when using FILTER_BOOL
  Fix #53778
  Issue 59387-2: make check with prefix more robust
  [PropertyInfo] Add missing test
  fix tests
  [Security][Validators] Review translations.
  [validator] Updated Dutch translation
  [FrameworkBundle] Fix wiring ConsoleProfilerListener
  [HttpKernel] Fix link to php doc
  [Lock] Make sure RedisStore will also support Valkey
  [Validator] Update sr_Cyrl 120:This value is not a valid slug.
  [Validator] Update sr_Latn 120:This value is not a valid slug.
  6.4 Missing translations for Italian (it) #59419
  tests(notifier): avoid failing SNS test with local AWS configuration
  Fix typo ratio comment
  chore: PropertyAccess - fix typo in DocBlock
  [Validator] Missing translations for Brazilian Portuguese (pt_BR)
  fix(dependency-injection): reset env vars with kernel.reset
  ...
2025-01-17 12:48:14 +01:00
Christian Flothmann
a5ee06ee38 Merge branch '7.1' into 7.2
* 7.1: (34 commits)
  improve amqp connection issues
  [Serializer] [ObjectNormalizer] Filter int when using FILTER_BOOL
  Fix #53778
  [PropertyInfo] Add missing test
  fix tests
  [Security][Validators] Review translations.
  [validator] Updated Dutch translation
  [FrameworkBundle] Fix wiring ConsoleProfilerListener
  [HttpKernel] Fix link to php doc
  [Validator] Update sr_Cyrl 120:This value is not a valid slug.
  [Validator] Update sr_Latn 120:This value is not a valid slug.
  6.4 Missing translations for Italian (it) #59419
  tests(notifier): avoid failing SNS test with local AWS configuration
  Fix typo ratio comment
  chore: PropertyAccess - fix typo in DocBlock
  [Validator] Missing translations for Brazilian Portuguese (pt_BR)
  fix(dependency-injection): reset env vars with kernel.reset
  [Translation][Validator] Review Russian translation (114 - 120)
  Review validator-related persian translation with id 120
  [Scheduler] Clarify description of exclusion time
  ...
2025-01-17 11:56:55 +01:00
Christian Flothmann
f4db3a3f24 Merge branch '6.4' into 7.1
* 6.4: (29 commits)
  Fix #53778
  [PropertyInfo] Add missing test
  fix tests
  [Security][Validators] Review translations.
  [validator] Updated Dutch translation
  [FrameworkBundle] Fix wiring ConsoleProfilerListener
  [HttpKernel] Fix link to php doc
  [Validator] Update sr_Cyrl 120:This value is not a valid slug.
  [Validator] Update sr_Latn 120:This value is not a valid slug.
  6.4 Missing translations for Italian (it) #59419
  tests(notifier): avoid failing SNS test with local AWS configuration
  [Validator] Missing translations for Brazilian Portuguese (pt_BR)
  [Translation][Validator] Review Russian translation (114 - 120)
  Review validator-related persian translation with id 120
  [Scheduler] Clarify description of exclusion time
  [HttpFoundation][FrameworkBundle] Reset Request's formats using the service resetter
  [Mailer] Fix SMTP stream EOF handling on Windows by using feof()
  [Translations] Make sure PL translations validators.pl.xlf follow the same style
  [Validator] Checked Turkish validators translations and confirmed
  [VarDumper] Fix blank strings display
  ...
2025-01-17 11:33:21 +01:00
Nicolas Grekas
43d963e637 [HttpKernel] Fix link to php doc 2025-01-14 15:54:07 +01:00
Simon André
f4a8c06e9a [Cache][HttpKernel] Add a noStore argument to the # attribute 2025-01-02 12:57:20 +01:00
Felix Eymonot
a1ecd5c472 [HttpKernel] [MapQueryString] added key argument to MapQueryString attribute 2024-12-10 18:37:16 +01:00
Alexandre Daubois
143526587e [HttpFoundation][HttpKernel] Remove dead code and useless casts 2024-07-19 13:15:43 +02:00
Alexander M. Turek
c307b0c1b7 Prefix all sprintf() calls 2024-06-20 17:52:34 +02:00
Rene Lima
47353bb3af [HttpKernel] Add MapUploadedFile attribute
Signed-off-by: Rene Lima <renedelima@gmail.com>
2024-04-18 18:51:06 +02:00
Yonel Ceruto
958982dbb4 map a list of items with MapRequestPayload attribute 2024-04-05 15:59:16 -04:00
Nicolas Grekas
8e2f7b2b3f minor #51971 [DependencyInjection][HttpKernel] Add PHPDoc to attribute classes and properties (alexandre-daubois)
This PR was merged into the 7.1 branch.

Discussion
----------

[DependencyInjection][HttpKernel] Add PHPDoc to attribute classes and properties

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Part of https://github.com/symfony/symfony/issues/51920
| License       | MIT

Friendly ping `@GromNaN`, is that what you had in mind? 🙂

Commits
-------

a9030f1aea [DependencyInjection][HttpKernel] Add PHPDoc to attribute classes and properties
2024-01-02 14:18:38 +01:00
Alexandre Daubois
0c0357ca3c [DependencyInjection][HttpKernel] Add PHPDoc to attribute classes and properties 2024-01-02 14:18:32 +01:00
Ionut Enache
3f17a2f064 [HttpKernel] Add support for custom HTTP status code for the MapQueryParameter attribute 2024-01-02 09:34:00 +02:00
Nicolas Grekas
de00a52bf3 [HttpKernel] Add ControllerResolver::allowControllers() to define which callables are legit controllers when the _check_controller_is_allowed request attribute is set 2023-11-06 18:13:54 +01:00
muchafm
987409bb3c [HttpKernel] Improve PHPDoc on #[AsController] attribute 2023-10-27 09:46:48 +02:00
Jérôme Tamarelle
b15a5edf41 [HttpFoundation]  Improve PHPDoc of Cache attribute 2023-10-11 18:54:47 +02:00
zim32
fe93cfcdd7 [HttpKernel] RequestPayloadValueResolver Add support for custom http status code 2023-08-01 10:56:47 +02:00
Nicolas Grekas
faa54763ab [HttpKernel] Fix handling of MapRequest* attributes 2023-05-02 16:10:51 +02:00
Renan
a6424977b9 [HttpKernel] Enhance MapQueryString adding validation group 2023-04-20 19:20:29 +02:00
Renan
2aa4ecc829 [HttpKernel] Enhance MapRequestPayload adding format and validation group
apply feedbacks

revert argument type

better properties name

attempt to fix CI

static providers
2023-04-19 20:53:13 +02:00
Nicolas Grekas
2a575ac1e3 Register QueryParameterValueResolver as "controller.targeted_value_resolver" 2023-04-14 13:28:53 +02:00
Ruud Kamphuis
22a767b0c6 [HttpKernel] Allow injecting query parameters in controllers by typing them with #[MapQueryParameter] attribute 2023-04-14 13:28:52 +02:00
Konstantin Myakshin
6ff86a31fe [HttpKernel] Create Attributes #[MapRequestPayload] and #[MapQueryString] to map Request input to typed objects 2023-04-14 12:11:03 +02:00
Nicolas Grekas
8eefedeb2d [HttpKernel] Renamed "pinned" to "targeted" for value resolvers 2023-03-09 14:05:53 +01:00
Mathieu
5f9154e0de [HttpKernel] Introduce pinnable value resolvers with #[ValueResolver] and #[AsPinnedValueResolver] 2023-03-06 10:26:47 +01:00
Fabien Potencier
ec65e5684a [HttpKernel] Rename HttpStatus atribute to WithHttpStatus 2023-01-05 07:47:23 +01:00
Dejan Angelov
0634c74397 [HttpKernel] Allow using #[WithLogLevel] for setting custom log level for exceptions 2023-01-05 07:42:37 +01:00
Dejan Angelov
cba4c84925 [HttpKernel] Allow using #[HttpStatus] for setting status code and headers for HTTP exceptions 2022-12-21 18:24:33 +01:00
Nicolas Grekas
af68c28c75 [HttpKernel] Add #[Cache] to describe the default HTTP cache headers on controllers 2022-07-12 15:52:22 +02:00
Tim Goudriaan
2e9a7df4cf [HttpKernel] Add DateTimeValueResolver 2022-03-24 13:54:46 +01:00
Nicolas Grekas
22ebd0adf8 [HttpKernel] remove deprecated features 2021-07-04 12:33:14 +02:00
Nicolas Grekas
498c4f3b43 [HttpKernel] Add #[AsController] attribute for declaring listeners on PHP 8 2021-03-23 18:56:31 +01:00
Robin Chalas
d162d4514e [HttpKernel] Handle multi-attribute controller arguments 2021-02-26 01:25:47 +01:00
Jérôme Vasseur
f7f6e36100 [RFC][HttpKernel][Security] Allowed adding attributes on controller arguments that will be passed to argument resolvers. 2020-09-12 10:22:10 +02:00