MapRequestPayload.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Attribute;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestPayloadValueResolver;
  13. use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
  14. use Symfony\Component\Validator\Constraints\GroupSequence;
  15. /**
  16. * Controller parameter tag to map the request content to typed object and validate it.
  17. *
  18. * @author Konstantin Myakshin <molodchick@gmail.com>
  19. */
  20. #[\Attribute(\Attribute::TARGET_PARAMETER)]
  21. class MapRequestPayload extends ValueResolver
  22. {
  23. public ArgumentMetadata $metadata;
  24. /**
  25. * @param array<string>|string|null $acceptFormat The payload formats to accept (i.e. "json", "xml")
  26. * @param array<string, mixed> $serializationContext The serialization context to use when deserializing the payload
  27. * @param string|GroupSequence|array<string>|null $validationGroups The validation groups to use when validating the query string mapping
  28. * @param class-string $resolver The class name of the resolver to use
  29. * @param int $validationFailedStatusCode The HTTP code to return if the validation fails
  30. * @param class-string|string|null $type The element type for array deserialization
  31. */
  32. public function __construct(
  33. public readonly array|string|null $acceptFormat = null,
  34. public readonly array $serializationContext = [],
  35. public readonly string|GroupSequence|array|null $validationGroups = null,
  36. string $resolver = RequestPayloadValueResolver::class,
  37. public readonly int $validationFailedStatusCode = Response::HTTP_UNPROCESSABLE_ENTITY,
  38. public readonly ?string $type = null,
  39. ) {
  40. parent::__construct($resolver);
  41. }
  42. }