MapQueryParameter.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\QueryParameterValueResolver;
  13. use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
  14. /**
  15. * Can be used to pass a query parameter to a controller argument.
  16. *
  17. * @author Ruud Kamphuis <ruud@ticketswap.com>
  18. * @author Ionut Enache <i.ovidiuenache@yahoo.com>
  19. */
  20. #[\Attribute(\Attribute::TARGET_PARAMETER)]
  21. final class MapQueryParameter extends ValueResolver
  22. {
  23. /**
  24. * @see https://php.net/manual/filter.constants for filter, flags and options
  25. *
  26. * @param string|null $name The name of the query parameter; if null, the name of the argument in the controller will be used
  27. * @param (FILTER_VALIDATE_*)|(FILTER_SANITIZE_*)|null $filter The filter to pass to "filter_var()"
  28. * @param int-mask-of<(FILTER_FLAG_*)|FILTER_NULL_ON_FAILURE> $flags The flags to pass to "filter_var()"
  29. * @param array $options The options to pass to "filter_var()"
  30. * @param class-string<ValueResolverInterface>|string $resolver The name of the resolver to use
  31. */
  32. public function __construct(
  33. public ?string $name = null,
  34. public ?int $filter = null,
  35. public int $flags = 0,
  36. public array $options = [],
  37. string $resolver = QueryParameterValueResolver::class,
  38. public int $validationFailedStatusCode = Response::HTTP_NOT_FOUND,
  39. ) {
  40. parent::__construct($resolver);
  41. }
  42. }