2016-04-17 13:42:52 +02:00
|
|
|
<?php
|
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-02-17 20:28:34 +01:00
|
|
|
use Throwable;
|
2018-10-28 08:24:06 +01:00
|
|
|
use function sprintf;
|
|
|
|
|
|
2016-04-17 13:42:52 +02:00
|
|
|
class InvalidShortCodeException extends RuntimeException
|
|
|
|
|
{
|
2019-02-17 20:28:34 +01:00
|
|
|
public static function fromCharset(string $shortCode, string $charSet, ?Throwable $previous = null): self
|
2016-04-17 13:42:52 +02:00
|
|
|
{
|
2018-09-15 11:54:58 +02:00
|
|
|
$code = $previous !== null ? $previous->getCode() : -1;
|
2016-04-17 13:42:52 +02:00
|
|
|
return new static(
|
2018-10-28 08:24:06 +01:00
|
|
|
sprintf('Provided short code "%s" does not match the char set "%s"', $shortCode, $charSet),
|
2016-04-17 13:42:52 +02:00
|
|
|
$code,
|
|
|
|
|
$previous
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-08-21 16:52:26 +02:00
|
|
|
|
2018-11-17 19:23:25 +01:00
|
|
|
public static function fromNotFoundShortCode(string $shortCode): self
|
2016-08-21 16:52:26 +02:00
|
|
|
{
|
2018-10-28 08:24:06 +01:00
|
|
|
return new static(sprintf('Provided short code "%s" does not belong to a short URL', $shortCode));
|
2016-08-21 16:52:26 +02:00
|
|
|
}
|
2016-04-17 13:42:52 +02:00
|
|
|
}
|