2017-10-21 18:18:57 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2017-10-21 18:18:57 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shlinkio\Shlink\Core\Exception;
|
|
|
|
|
2019-11-25 01:32:37 +03:00
|
|
|
use Fig\Http\Message\StatusCodeInterface;
|
|
|
|
use Zend\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
|
|
|
|
use Zend\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
|
|
|
|
|
2018-10-28 10:34:02 +03:00
|
|
|
use function sprintf;
|
|
|
|
|
2019-11-25 01:32:37 +03:00
|
|
|
class NonUniqueSlugException extends InvalidArgumentException implements ProblemDetailsExceptionInterface
|
2017-10-21 18:18:57 +03:00
|
|
|
{
|
2019-11-25 01:32:37 +03:00
|
|
|
use CommonProblemDetailsExceptionTrait;
|
|
|
|
|
|
|
|
private const TITLE = 'Invalid custom slug';
|
|
|
|
public const TYPE = 'INVALID_SLUG';
|
|
|
|
|
2019-10-01 22:42:35 +03:00
|
|
|
public static function fromSlug(string $slug, ?string $domain): self
|
2017-10-21 18:18:57 +03:00
|
|
|
{
|
2019-10-01 22:42:35 +03:00
|
|
|
$suffix = '';
|
|
|
|
if ($domain !== null) {
|
|
|
|
$suffix = sprintf(' for domain "%s"', $domain);
|
|
|
|
}
|
|
|
|
|
2019-11-25 01:32:37 +03:00
|
|
|
$e = new self(sprintf('Provided slug "%s" is already in use%s.', $slug, $suffix));
|
|
|
|
|
|
|
|
$e->detail = $e->getMessage();
|
|
|
|
$e->title = self::TITLE;
|
|
|
|
$e->type = self::TYPE;
|
|
|
|
$e->status = StatusCodeInterface::STATUS_BAD_REQUEST;
|
|
|
|
|
|
|
|
return $e;
|
2017-10-21 18:18:57 +03:00
|
|
|
}
|
|
|
|
}
|