MissingMandatoryParametersException.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Routing\Exception;
  11. /**
  12. * Exception thrown when a route cannot be generated because of missing
  13. * mandatory parameters.
  14. *
  15. * @author Alexandre Salomé <alexandre.salome@gmail.com>
  16. */
  17. class MissingMandatoryParametersException extends \InvalidArgumentException implements ExceptionInterface
  18. {
  19. private string $routeName = '';
  20. private array $missingParameters = [];
  21. /**
  22. * @param string[] $missingParameters
  23. */
  24. public function __construct(string $routeName = '', array $missingParameters = [], int $code = 0, ?\Throwable $previous = null)
  25. {
  26. $this->routeName = $routeName;
  27. $this->missingParameters = $missingParameters;
  28. $message = sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', $missingParameters), $routeName);
  29. parent::__construct($message, $code, $previous);
  30. }
  31. /**
  32. * @return string[]
  33. */
  34. public function getMissingParameters(): array
  35. {
  36. return $this->missingParameters;
  37. }
  38. public function getRouteName(): string
  39. {
  40. return $this->routeName;
  41. }
  42. }