MethodNotAllowedException.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. $this->allowedMethods = array_map('strtoupper', $allowedMethods);
  27. parent::__construct($message, $code, $previous);
  28. }
  29. /**
  30. * Gets the allowed HTTP methods.
  31. *
  32. * @return string[]
  33. */
  34. public function getAllowedMethods()
  35. {
  36. return $this->allowedMethods;
  37. }
  38. }