2016-04-17 13:42:52 +02:00
|
|
|
<?php
|
2019-10-05 17:26:10 +02:00
|
|
|
|
2017-10-12 10:13:20 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2016-07-19 18:01:39 +02:00
|
|
|
namespace Shlinkio\Shlink\Core\Exception;
|
2016-04-17 13:42:52 +02:00
|
|
|
|
2019-11-23 13:41:07 +01:00
|
|
|
use Fig\Http\Message\StatusCodeInterface;
|
2020-01-01 21:11:53 +01:00
|
|
|
use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
|
|
|
|
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
2019-02-26 22:56:43 +01:00
|
|
|
|
2018-10-28 08:24:06 +01:00
|
|
|
use function sprintf;
|
|
|
|
|
|
2019-11-24 23:11:25 +01:00
|
|
|
class ShortUrlNotFoundException extends DomainException implements ProblemDetailsExceptionInterface
|
2016-04-17 13:42:52 +02:00
|
|
|
{
|
2019-11-23 13:41:07 +01:00
|
|
|
use CommonProblemDetailsExceptionTrait;
|
|
|
|
|
|
2019-11-24 23:11:25 +01:00
|
|
|
private const TITLE = 'Short URL not found';
|
2019-11-26 22:12:52 +01:00
|
|
|
private const TYPE = 'INVALID_SHORTCODE';
|
2016-08-21 16:52:26 +02:00
|
|
|
|
2019-11-25 18:54:25 +01:00
|
|
|
public static function fromNotFoundShortCode(string $shortCode, ?string $domain = null): self
|
2016-08-21 16:52:26 +02:00
|
|
|
{
|
2019-11-25 18:54:25 +01:00
|
|
|
$suffix = $domain === null ? '' : sprintf(' for domain "%s"', $domain);
|
|
|
|
|
$e = new self(sprintf('No URL found with short code "%s"%s', $shortCode, $suffix));
|
2019-11-24 12:41:12 +01:00
|
|
|
|
2019-11-23 13:41:07 +01:00
|
|
|
$e->detail = $e->getMessage();
|
|
|
|
|
$e->title = self::TITLE;
|
|
|
|
|
$e->type = self::TYPE;
|
|
|
|
|
$e->status = StatusCodeInterface::STATUS_NOT_FOUND;
|
2019-11-27 20:18:36 +01:00
|
|
|
$e->additional = ['shortCode' => $shortCode];
|
|
|
|
|
|
|
|
|
|
if ($domain !== null) {
|
|
|
|
|
$e->additional['domain'] = $domain;
|
|
|
|
|
}
|
2019-11-23 13:41:07 +01:00
|
|
|
|
|
|
|
|
return $e;
|
2016-08-21 16:52:26 +02:00
|
|
|
}
|
2016-04-17 13:42:52 +02:00
|
|
|
}
|