InvalidUrlException.php 989 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\Core\Exception;
  4. use Fig\Http\Message\StatusCodeInterface;
  5. use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
  6. use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
  7. use Throwable;
  8. use function sprintf;
  9. class InvalidUrlException extends DomainException implements ProblemDetailsExceptionInterface
  10. {
  11. use CommonProblemDetailsExceptionTrait;
  12. private const TITLE = 'Invalid URL';
  13. private const TYPE = 'INVALID_URL';
  14. public static function fromUrl(string $url, ?Throwable $previous = null): self
  15. {
  16. $status = StatusCodeInterface::STATUS_BAD_REQUEST;
  17. $e = new self(sprintf('Provided URL %s is invalid. Try with a different one.', $url), $status, $previous);
  18. $e->detail = $e->getMessage();
  19. $e->title = self::TITLE;
  20. $e->type = self::TYPE;
  21. $e->status = $status;
  22. $e->additional = ['url' => $url];
  23. return $e;
  24. }
  25. }