Added logic to check if a short code is in use and regenerate it otherwise

This commit is contained in:
Alejandro Celaya
2019-10-11 11:09:33 +02:00
parent 8f2e78c946
commit 9538f474de
7 changed files with 90 additions and 42 deletions

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Exception;
class ShortCodeCannotBeRegeneratedException extends RuntimeException
{
/** @var @bool */
private $reasonIsSlug = false;
public static function forShortUrlWithCustomSlug(): self
{
$e = new self('The short code cannot be regenerated on ShortUrls where a custom slug was provided.');
$e->reasonIsSlug = true;
return $e;
}
public static function forShortUrlAlreadyPersisted(): self
{
return new self('The short code can be regenerated only on new ShortUrls which have not been persisted yet.');
}
public function reasonIsSlug(): bool
{
return $this->reasonIsSlug;
}
}