You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

3 years ago
  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. * The resource was found but the request method is not allowed.
  13. *
  14. * This exception should trigger an HTTP 405 response in your application code.
  15. *
  16. * @author Kris Wallsmith <kris@symfony.com>
  17. */
  18. class MethodNotAllowedException extends \RuntimeException implements ExceptionInterface
  19. {
  20. protected $allowedMethods = [];
  21. /**
  22. * @param string[] $allowedMethods
  23. */
  24. public function __construct(array $allowedMethods, ?string $message = '', int $code = 0, \Throwable $previous = null)
  25. {
  26. if (null === $message) {
  27. trigger_deprecation('symfony/routing', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__);
  28. $message = '';
  29. }
  30. $this->allowedMethods = array_map('strtoupper', $allowedMethods);
  31. parent::__construct($message, $code, $previous);
  32. }
  33. /**
  34. * Gets the allowed HTTP methods.
  35. *
  36. * @return string[]
  37. */
  38. public function getAllowedMethods()
  39. {
  40. return $this->allowedMethods;
  41. }
  42. }