mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-23 07:33:58 -06:00
More classes renamed and fixes for usage of the short code concept in place of short URL
This commit is contained in:
parent
7ab993b764
commit
80fe3a73e2
@ -5,7 +5,7 @@ namespace Shlinkio\Shlink\Core\Model;
|
||||
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
final class CreateShortCodeData
|
||||
final class CreateShortUrlData
|
||||
{
|
||||
/**
|
||||
* @var UriInterface
|
@ -9,7 +9,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
|
||||
use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
|
||||
use Shlinkio\Shlink\Core\Model\CreateShortCodeData;
|
||||
use Shlinkio\Shlink\Core\Model\CreateShortUrlData;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
|
||||
use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer;
|
||||
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
||||
@ -52,10 +52,10 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$shortCodeData = $this->buildUrlToShortCodeData($request);
|
||||
$shortCodeMeta = $shortCodeData->getMeta();
|
||||
$longUrl = $shortCodeData->getLongUrl();
|
||||
$customSlug = $shortCodeMeta->getCustomSlug();
|
||||
$shortUrlData = $this->buildShortUrlData($request);
|
||||
$shortUrlMeta = $shortUrlData->getMeta();
|
||||
$longUrl = $shortUrlData->getLongUrl();
|
||||
$customSlug = $shortUrlMeta->getCustomSlug();
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->logger->warning('Provided data is invalid.' . PHP_EOL . $e);
|
||||
return new JsonResponse([
|
||||
@ -67,11 +67,11 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
try {
|
||||
$shortUrl = $this->urlShortener->urlToShortCode(
|
||||
$longUrl,
|
||||
$shortCodeData->getTags(),
|
||||
$shortCodeMeta->getValidSince(),
|
||||
$shortCodeMeta->getValidUntil(),
|
||||
$shortUrlData->getTags(),
|
||||
$shortUrlMeta->getValidSince(),
|
||||
$shortUrlMeta->getValidUntil(),
|
||||
$customSlug,
|
||||
$shortCodeMeta->getMaxVisits()
|
||||
$shortUrlMeta->getMaxVisits()
|
||||
);
|
||||
$transformer = new ShortUrlDataTransformer($this->domainConfig);
|
||||
|
||||
@ -95,7 +95,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
),
|
||||
], self::STATUS_BAD_REQUEST);
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->error('Unexpected error creating shortcode.' . PHP_EOL . $e);
|
||||
$this->logger->error('Unexpected error creating short url.' . PHP_EOL . $e);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::UNKNOWN_ERROR,
|
||||
'message' => $this->translator->translate('Unexpected error occurred'),
|
||||
@ -105,8 +105,8 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return CreateShortCodeData
|
||||
* @return CreateShortUrlData
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
abstract protected function buildUrlToShortCodeData(Request $request): CreateShortCodeData;
|
||||
abstract protected function buildShortUrlData(Request $request): CreateShortUrlData;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Core\Model\CreateShortCodeData;
|
||||
use Shlinkio\Shlink\Core\Model\CreateShortUrlData;
|
||||
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\AbstractCreateShortUrlAction;
|
||||
use Zend\Diactoros\Uri;
|
||||
@ -17,18 +17,18 @@ class CreateShortUrlAction extends AbstractCreateShortUrlAction
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return CreateShortCodeData
|
||||
* @return CreateShortUrlData
|
||||
* @throws InvalidArgumentException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function buildUrlToShortCodeData(Request $request): CreateShortCodeData
|
||||
protected function buildShortUrlData(Request $request): CreateShortUrlData
|
||||
{
|
||||
$postData = (array) $request->getParsedBody();
|
||||
if (! isset($postData['longUrl'])) {
|
||||
throw new InvalidArgumentException($this->translator->translate('A URL was not provided'));
|
||||
}
|
||||
|
||||
return new CreateShortCodeData(
|
||||
return new CreateShortUrlData(
|
||||
new Uri($postData['longUrl']),
|
||||
(array) ($postData['tags'] ?? []),
|
||||
ShortUrlMeta::createFromParams(
|
||||
|
@ -6,9 +6,8 @@ namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Core\Model\CreateShortCodeData;
|
||||
use Shlinkio\Shlink\Core\Model\CreateShortUrlData;
|
||||
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\AbstractCreateShortUrlAction;
|
||||
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
|
||||
use Zend\Diactoros\Uri;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
@ -36,11 +35,11 @@ class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return CreateShortCodeData
|
||||
* @return CreateShortUrlData
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function buildUrlToShortCodeData(Request $request): CreateShortCodeData
|
||||
protected function buildShortUrlData(Request $request): CreateShortUrlData
|
||||
{
|
||||
$query = $request->getQueryParams();
|
||||
|
||||
@ -56,6 +55,6 @@ class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction
|
||||
throw new InvalidArgumentException($this->translator->translate('A URL was not provided'));
|
||||
}
|
||||
|
||||
return new CreateShortCodeData(new Uri($query['longUrl']));
|
||||
return new CreateShortUrlData(new Uri($query['longUrl']));
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ use Zend\I18n\Translator\TranslatorInterface;
|
||||
|
||||
class GetVisitsAction extends AbstractRestAction
|
||||
{
|
||||
protected const ROUTE_PATH = '/short-codes/{shortCode}/visits';
|
||||
protected const ROUTE_PATH = '/short-urls/{shortCode}/visits';
|
||||
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
|
||||
|
||||
/**
|
||||
@ -58,7 +58,7 @@ class GetVisitsAction extends AbstractRestAction
|
||||
],
|
||||
]);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->logger->warning('Provided nonexistent shortcode' . PHP_EOL . $e);
|
||||
$this->logger->warning('Provided nonexistent short code' . PHP_EOL . $e);
|
||||
return new JsonResponse([
|
||||
'error' => RestUtils::getRestErrorCodeFromException($e),
|
||||
'message' => sprintf(
|
||||
|
@ -10,6 +10,7 @@ use Shlinkio\Shlink\Rest\Exception as Rest;
|
||||
class RestUtils
|
||||
{
|
||||
public const INVALID_SHORTCODE_ERROR = 'INVALID_SHORTCODE';
|
||||
// FIXME Should be INVALID_SHORT_URL_DELETION
|
||||
public const INVALID_SHORTCODE_DELETION_ERROR = 'INVALID_SHORTCODE_DELETION';
|
||||
public const INVALID_URL_ERROR = 'INVALID_URL';
|
||||
public const INVALID_ARGUMENT_ERROR = 'INVALID_ARGUMENT';
|
||||
|
Loading…
Reference in New Issue
Block a user