Removed translations from Rest module

This commit is contained in:
Alejandro Celaya
2018-11-18 16:28:04 +01:00
parent c5015f5828
commit 90732a4fad
33 changed files with 70 additions and 358 deletions

View File

@@ -38,14 +38,13 @@ return [
], ],
ConfigAbstractFactory::class => [ ConfigAbstractFactory::class => [
Authentication\Plugin\AuthorizationHeaderPlugin::class => [Authentication\JWTService::class, 'translator'], Authentication\Plugin\AuthorizationHeaderPlugin::class => [Authentication\JWTService::class],
Authentication\Plugin\ApiKeyHeaderPlugin::class => [Service\ApiKeyService::class, 'translator'], Authentication\Plugin\ApiKeyHeaderPlugin::class => [Service\ApiKeyService::class],
Authentication\RequestToHttpAuthPlugin::class => [Authentication\AuthenticationPluginManager::class], Authentication\RequestToHttpAuthPlugin::class => [Authentication\AuthenticationPluginManager::class],
Middleware\AuthenticationMiddleware::class => [ Middleware\AuthenticationMiddleware::class => [
Authentication\RequestToHttpAuthPlugin::class, Authentication\RequestToHttpAuthPlugin::class,
'translator',
'config.auth.routes_whitelist', 'config.auth.routes_whitelist',
'Logger_Shlink', 'Logger_Shlink',
], ],

View File

@@ -7,7 +7,6 @@ use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Options\AppOptions;
use Shlinkio\Shlink\Core\Service; use Shlinkio\Shlink\Core\Service;
use Shlinkio\Shlink\Rest\Service\ApiKeyService; use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use Zend\I18n\Translator\Translator;
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\Factory\InvokableFactory;
@@ -44,52 +43,32 @@ return [
Authentication\JWTService::class => [AppOptions::class], Authentication\JWTService::class => [AppOptions::class],
ApiKeyService::class => ['em'], ApiKeyService::class => ['em'],
Action\AuthenticateAction::class => [ Action\AuthenticateAction::class => [ApiKeyService::class, Authentication\JWTService::class, 'Logger_Shlink'],
ApiKeyService::class,
Authentication\JWTService::class,
'translator',
'Logger_Shlink',
],
Action\ShortUrl\CreateShortUrlAction::class => [ Action\ShortUrl\CreateShortUrlAction::class => [
Service\UrlShortener::class, Service\UrlShortener::class,
'translator',
'config.url_shortener.domain', 'config.url_shortener.domain',
'Logger_Shlink', 'Logger_Shlink',
], ],
Action\ShortUrl\SingleStepCreateShortUrlAction::class => [ Action\ShortUrl\SingleStepCreateShortUrlAction::class => [
Service\UrlShortener::class, Service\UrlShortener::class,
'translator',
ApiKeyService::class, ApiKeyService::class,
'config.url_shortener.domain', 'config.url_shortener.domain',
'Logger_Shlink', 'Logger_Shlink',
], ],
Action\ShortUrl\EditShortUrlAction::class => [Service\ShortUrlService::class, 'translator', 'Logger_Shlink'], Action\ShortUrl\EditShortUrlAction::class => [Service\ShortUrlService::class, 'Logger_Shlink'],
Action\ShortUrl\DeleteShortUrlAction::class => [ Action\ShortUrl\DeleteShortUrlAction::class => [Service\ShortUrl\DeleteShortUrlService::class, 'Logger_Shlink'],
Service\ShortUrl\DeleteShortUrlService::class, Action\ShortUrl\ResolveShortUrlAction::class => [Service\UrlShortener::class, 'config.url_shortener.domain'],
'translator', Action\Visit\GetVisitsAction::class => [Service\VisitsTracker::class, 'Logger_Shlink'],
'Logger_Shlink',
],
Action\ShortUrl\ResolveShortUrlAction::class => [
Service\UrlShortener::class,
'translator',
'config.url_shortener.domain',
],
Action\Visit\GetVisitsAction::class => [Service\VisitsTracker::class, 'translator', 'Logger_Shlink'],
Action\ShortUrl\ListShortUrlsAction::class => [ Action\ShortUrl\ListShortUrlsAction::class => [
Service\ShortUrlService::class, Service\ShortUrlService::class,
'translator',
'config.url_shortener.domain', 'config.url_shortener.domain',
'Logger_Shlink', 'Logger_Shlink',
], ],
Action\ShortUrl\EditShortUrlTagsAction::class => [ Action\ShortUrl\EditShortUrlTagsAction::class => [Service\ShortUrlService::class, 'Logger_Shlink'],
Service\ShortUrlService::class,
'translator',
'Logger_Shlink',
],
Action\Tag\ListTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], Action\Tag\ListTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class],
Action\Tag\DeleteTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], Action\Tag\DeleteTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class],
Action\Tag\CreateTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], Action\Tag\CreateTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class],
Action\Tag\UpdateTagAction::class => [Service\Tag\TagService::class, Translator::class, LoggerInterface::class], Action\Tag\UpdateTagAction::class => [Service\Tag\TagService::class, LoggerInterface::class],
], ],
]; ];

View File

@@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
return [
'translator' => [
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => __DIR__ . '/../lang',
'pattern' => '%s.mo',
],
],
],
];

Binary file not shown.

View File

@@ -1,110 +0,0 @@
msgid ""
msgstr ""
"Project-Id-Version: Shlink 1.0\n"
"POT-Creation-Date: 2018-09-29 10:08+0200\n"
"PO-Revision-Date: 2018-09-29 10:08+0200\n"
"Last-Translator: Alejandro Celaya <alejandro@alejandrocelaya.com>\n"
"Language-Team: \n"
"Language: es_ES\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.6\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: translate;translatePlural\n"
"X-Poedit-SearchPath-0: config\n"
"X-Poedit-SearchPath-1: src\n"
msgid "You have to provide a valid API key under the \"apiKey\" param name."
msgstr ""
"Debes proporcionar una clave de API válida bajo el nombre de parámetro "
"\"apiKey\"."
msgid "Provided API key does not exist or is invalid."
msgstr "La clave de API proporcionada no existe o es inválida."
#, php-format
msgid "Provided URL %s is invalid. Try with a different one."
msgstr "La URL proporcionada \"%s\" es inválida. Prueba con una diferente."
#, php-format
msgid "Provided slug %s is already in use. Try with a different one."
msgstr "El slug proporcionado \"%s\" ya está en uso. Prueba con uno diferente."
msgid "Unexpected error occurred"
msgstr "Ocurrió un error inesperado"
msgid "A URL was not provided"
msgstr "No se ha proporcionado una URL"
#, php-format
msgid "No URL found for short code \"%s\""
msgstr "No se ha encontrado ninguna URL para el código corto \"%s\""
#, php-format
msgid ""
"It is not possible to delete URL with short code \"%s\" because it has "
"reached more than \"%s\" visits."
msgstr ""
"No es posible eliminar la URL con el código corto \"%s\" porque ha alcanzado "
"más de \"%s\" visitas."
msgid "Provided data is invalid."
msgstr "Los datos proporcionados son inválidos."
msgid "A list of tags was not provided"
msgstr "No se ha proporcionado una lista de etiquetas"
#, php-format
msgid "Provided short code \"%s\" has an invalid format"
msgstr "El código corto proporcionado \"%s\" tiene un formato no inválido"
msgid "No API key was provided or it is not valid"
msgstr "No se ha proporcionado una clave de API o esta es inválida"
msgid ""
"You have to provide both 'oldName' and 'newName' params in order to properly "
"rename the tag"
msgstr ""
"Debes proporcionar tanto el parámetro 'oldName' como 'newName' para poder "
"renombrar la etiqueta correctamente"
#, php-format
msgid "It wasn't possible to find a tag with name '%s'"
msgstr "No fue posible encontrar una etiqueta con el nombre '%s'"
#, php-format
msgid "Provided short code %s does not exist"
msgstr "El código corto \"%s\" proporcionado no existe"
#, php-format
msgid "You need to provide the Bearer type in the %s header."
msgstr "Debes proporcionar el typo Bearer en la cabecera %s."
#, php-format
msgid "Provided authorization type %s is not supported. Use Bearer instead."
msgstr ""
"El tipo de autorización proporcionado %s no está soportado. En vez de eso "
"utiliza Bearer."
#, fuzzy, php-format
#| msgid ""
#| "Missing or invalid auth token provided. Perform a new authentication "
#| "request and send provided token on every new request on the \"%s\" header"
msgid ""
"Missing or invalid auth token provided. Perform a new authentication request "
"and send provided token on every new request on the %s header"
msgstr ""
"No se ha proporcionado token de autenticación o este es inválido. Realiza "
"una nueva petición de autenticación y envía el token proporcionado en cada "
"nueva petición en la cabecera \"%s\""
#, php-format
msgid ""
"Expected one of the following authentication headers, but none were "
"provided, [\"%s\"]"
msgstr ""
"Se esperaba una de las siguientes cabeceras de autenticación, pero no se "
"proporcionó ninguna, [\"%s\"]"

View File

@@ -11,17 +11,12 @@ use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
class AuthenticateAction extends AbstractRestAction class AuthenticateAction extends AbstractRestAction
{ {
protected const ROUTE_PATH = '/authenticate'; protected const ROUTE_PATH = '/authenticate';
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST]; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST];
/**
* @var TranslatorInterface
*/
private $translator;
/** /**
* @var ApiKeyService|ApiKeyServiceInterface * @var ApiKeyService|ApiKeyServiceInterface
*/ */
@@ -34,11 +29,9 @@ class AuthenticateAction extends AbstractRestAction
public function __construct( public function __construct(
ApiKeyServiceInterface $apiKeyService, ApiKeyServiceInterface $apiKeyService,
JWTServiceInterface $jwtService, JWTServiceInterface $jwtService,
TranslatorInterface $translator,
LoggerInterface $logger = null LoggerInterface $logger = null
) { ) {
parent::__construct($logger); parent::__construct($logger);
$this->translator = $translator;
$this->apiKeyService = $apiKeyService; $this->apiKeyService = $apiKeyService;
$this->jwtService = $jwtService; $this->jwtService = $jwtService;
} }
@@ -54,9 +47,7 @@ class AuthenticateAction extends AbstractRestAction
if (! isset($authData['apiKey'])) { if (! isset($authData['apiKey'])) {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_ARGUMENT_ERROR, 'error' => RestUtils::INVALID_ARGUMENT_ERROR,
'message' => $this->translator->translate( 'message' => 'You have to provide a valid API key under the "apiKey" param name.',
'You have to provide a valid API key under the "apiKey" param name.'
),
], self::STATUS_BAD_REQUEST); ], self::STATUS_BAD_REQUEST);
} }
@@ -65,7 +56,7 @@ class AuthenticateAction extends AbstractRestAction
if ($apiKey === null || ! $apiKey->isValid()) { if ($apiKey === null || ! $apiKey->isValid()) {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_API_KEY_ERROR, 'error' => RestUtils::INVALID_API_KEY_ERROR,
'message' => $this->translator->translate('Provided API key does not exist or is invalid.'), 'message' => 'Provided API key does not exist or is invalid.',
], self::STATUS_UNAUTHORIZED); ], self::STATUS_UNAUTHORIZED);
} }

View File

@@ -16,7 +16,6 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Throwable; use Throwable;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
use function sprintf; use function sprintf;
abstract class AbstractCreateShortUrlAction extends AbstractRestAction abstract class AbstractCreateShortUrlAction extends AbstractRestAction
@@ -29,20 +28,14 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
* @var array * @var array
*/ */
private $domainConfig; private $domainConfig;
/**
* @var TranslatorInterface
*/
protected $translator;
public function __construct( public function __construct(
UrlShortenerInterface $urlShortener, UrlShortenerInterface $urlShortener,
TranslatorInterface $translator,
array $domainConfig, array $domainConfig,
LoggerInterface $logger = null LoggerInterface $logger = null
) { ) {
parent::__construct($logger); parent::__construct($logger);
$this->urlShortener = $urlShortener; $this->urlShortener = $urlShortener;
$this->translator = $translator;
$this->domainConfig = $domainConfig; $this->domainConfig = $domainConfig;
} }
@@ -82,25 +75,19 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction
$this->logger->warning('Provided Invalid URL. {e}', ['e' => $e]); $this->logger->warning('Provided Invalid URL. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => sprintf( 'message' => sprintf('Provided URL %s is invalid. Try with a different one.', $longUrl),
$this->translator->translate('Provided URL %s is invalid. Try with a different one.'),
$longUrl
),
], self::STATUS_BAD_REQUEST); ], self::STATUS_BAD_REQUEST);
} catch (NonUniqueSlugException $e) { } catch (NonUniqueSlugException $e) {
$this->logger->warning('Provided non-unique slug. {e}', ['e' => $e]); $this->logger->warning('Provided non-unique slug. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => sprintf( 'message' => sprintf('Provided slug %s is already in use. Try with a different one.', $customSlug),
$this->translator->translate('Provided slug %s is already in use. Try with a different one.'),
$customSlug
),
], self::STATUS_BAD_REQUEST); ], self::STATUS_BAD_REQUEST);
} catch (Throwable $e) { } catch (Throwable $e) {
$this->logger->error('Unexpected error creating short url. {e}', ['e' => $e]); $this->logger->error('Unexpected error creating short url. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::UNKNOWN_ERROR, 'error' => RestUtils::UNKNOWN_ERROR,
'message' => $this->translator->translate('Unexpected error occurred'), 'message' => 'Unexpected error occurred',
], self::STATUS_INTERNAL_SERVER_ERROR); ], self::STATUS_INTERNAL_SERVER_ERROR);
} }
} }

View File

@@ -8,7 +8,6 @@ use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException; use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Core\Model\CreateShortUrlData; use Shlinkio\Shlink\Core\Model\CreateShortUrlData;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta; use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Rest\Action\ShortUrl\AbstractCreateShortUrlAction;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
class CreateShortUrlAction extends AbstractCreateShortUrlAction class CreateShortUrlAction extends AbstractCreateShortUrlAction
@@ -26,7 +25,7 @@ class CreateShortUrlAction extends AbstractCreateShortUrlAction
{ {
$postData = (array) $request->getParsedBody(); $postData = (array) $request->getParsedBody();
if (! isset($postData['longUrl'])) { if (! isset($postData['longUrl'])) {
throw new InvalidArgumentException($this->translator->translate('A URL was not provided')); throw new InvalidArgumentException('A URL was not provided');
} }
return new CreateShortUrlData( return new CreateShortUrlData(

View File

@@ -12,7 +12,6 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\EmptyResponse; use Zend\Diactoros\Response\EmptyResponse;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
use function sprintf; use function sprintf;
class DeleteShortUrlAction extends AbstractRestAction class DeleteShortUrlAction extends AbstractRestAction
@@ -24,19 +23,11 @@ class DeleteShortUrlAction extends AbstractRestAction
* @var DeleteShortUrlServiceInterface * @var DeleteShortUrlServiceInterface
*/ */
private $deleteShortUrlService; private $deleteShortUrlService;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct( public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService, LoggerInterface $logger = null)
DeleteShortUrlServiceInterface $deleteShortUrlService, {
TranslatorInterface $translator,
LoggerInterface $logger = null
) {
parent::__construct($logger); parent::__construct($logger);
$this->deleteShortUrlService = $deleteShortUrlService; $this->deleteShortUrlService = $deleteShortUrlService;
$this->translator = $translator;
} }
/** /**
@@ -56,13 +47,12 @@ class DeleteShortUrlAction extends AbstractRestAction
); );
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), 'message' => sprintf('No URL found for short code "%s"', $shortCode),
], self::STATUS_NOT_FOUND); ], self::STATUS_NOT_FOUND);
} catch (Exception\DeleteShortUrlException $e) { } catch (Exception\DeleteShortUrlException $e) {
$this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]);
$messagePlaceholder = $this->translator->translate( $messagePlaceholder =
'It is not possible to delete URL with short code "%s" because it has reached more than "%s" visits.' 'It is not possible to delete URL with short code "%s" because it has reached more than "%s" visits.';
);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),

View File

@@ -13,7 +13,6 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\EmptyResponse; use Zend\Diactoros\Response\EmptyResponse;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
use function sprintf; use function sprintf;
class EditShortUrlAction extends AbstractRestAction class EditShortUrlAction extends AbstractRestAction
@@ -25,19 +24,11 @@ class EditShortUrlAction extends AbstractRestAction
* @var ShortUrlServiceInterface * @var ShortUrlServiceInterface
*/ */
private $shortUrlService; private $shortUrlService;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct( public function __construct(ShortUrlServiceInterface $shortUrlService, LoggerInterface $logger = null)
ShortUrlServiceInterface $shortUrlService, {
TranslatorInterface $translator,
LoggerInterface $logger = null
) {
parent::__construct($logger); parent::__construct($logger);
$this->shortUrlService = $shortUrlService; $this->shortUrlService = $shortUrlService;
$this->translator = $translator;
} }
/** /**
@@ -64,13 +55,13 @@ class EditShortUrlAction extends AbstractRestAction
$this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), 'message' => sprintf('No URL found for short code "%s"', $shortCode),
], self::STATUS_NOT_FOUND); ], self::STATUS_NOT_FOUND);
} catch (Exception\ValidationException $e) { } catch (Exception\ValidationException $e) {
$this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => $this->translator->translate('Provided data is invalid.'), 'message' => 'Provided data is invalid.',
], self::STATUS_BAD_REQUEST); ], self::STATUS_BAD_REQUEST);
} }
} }

View File

@@ -11,7 +11,6 @@ use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
use function sprintf; use function sprintf;
class EditShortUrlTagsAction extends AbstractRestAction class EditShortUrlTagsAction extends AbstractRestAction
@@ -23,19 +22,11 @@ class EditShortUrlTagsAction extends AbstractRestAction
* @var ShortUrlServiceInterface * @var ShortUrlServiceInterface
*/ */
private $shortUrlService; private $shortUrlService;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct( public function __construct(ShortUrlServiceInterface $shortUrlService, LoggerInterface $logger = null)
ShortUrlServiceInterface $shortUrlService, {
TranslatorInterface $translator,
LoggerInterface $logger = null
) {
parent::__construct($logger); parent::__construct($logger);
$this->shortUrlService = $shortUrlService; $this->shortUrlService = $shortUrlService;
$this->translator = $translator;
} }
/** /**
@@ -51,7 +42,7 @@ class EditShortUrlTagsAction extends AbstractRestAction
if (! isset($bodyParams['tags'])) { if (! isset($bodyParams['tags'])) {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_ARGUMENT_ERROR, 'error' => RestUtils::INVALID_ARGUMENT_ERROR,
'message' => $this->translator->translate('A list of tags was not provided'), 'message' => 'A list of tags was not provided',
], self::STATUS_BAD_REQUEST); ], self::STATUS_BAD_REQUEST);
} }
$tags = $bodyParams['tags']; $tags = $bodyParams['tags'];
@@ -62,7 +53,7 @@ class EditShortUrlTagsAction extends AbstractRestAction
} catch (InvalidShortCodeException $e) { } catch (InvalidShortCodeException $e) {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), 'message' => sprintf('No URL found for short code "%s"', $shortCode),
], self::STATUS_NOT_FOUND); ], self::STATUS_NOT_FOUND);
} }
} }

View File

@@ -13,7 +13,6 @@ use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
class ListShortUrlsAction extends AbstractRestAction class ListShortUrlsAction extends AbstractRestAction
{ {
@@ -26,10 +25,6 @@ class ListShortUrlsAction extends AbstractRestAction
* @var ShortUrlServiceInterface * @var ShortUrlServiceInterface
*/ */
private $shortUrlService; private $shortUrlService;
/**
* @var TranslatorInterface
*/
private $translator;
/** /**
* @var array * @var array
*/ */
@@ -37,13 +32,11 @@ class ListShortUrlsAction extends AbstractRestAction
public function __construct( public function __construct(
ShortUrlServiceInterface $shortUrlService, ShortUrlServiceInterface $shortUrlService,
TranslatorInterface $translator,
array $domainConfig, array $domainConfig,
LoggerInterface $logger = null LoggerInterface $logger = null
) { ) {
parent::__construct($logger); parent::__construct($logger);
$this->shortUrlService = $shortUrlService; $this->shortUrlService = $shortUrlService;
$this->translator = $translator;
$this->domainConfig = $domainConfig; $this->domainConfig = $domainConfig;
} }
@@ -64,7 +57,7 @@ class ListShortUrlsAction extends AbstractRestAction
$this->logger->error('Unexpected error while listing short URLs. {e}', ['e' => $e]); $this->logger->error('Unexpected error while listing short URLs. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::UNKNOWN_ERROR, 'error' => RestUtils::UNKNOWN_ERROR,
'message' => $this->translator->translate('Unexpected error occurred'), 'message' => 'Unexpected error occurred',
], self::STATUS_INTERNAL_SERVER_ERROR); ], self::STATUS_INTERNAL_SERVER_ERROR);
} }
} }

View File

@@ -14,7 +14,6 @@ use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
use function sprintf; use function sprintf;
class ResolveShortUrlAction extends AbstractRestAction class ResolveShortUrlAction extends AbstractRestAction
@@ -26,10 +25,6 @@ class ResolveShortUrlAction extends AbstractRestAction
* @var UrlShortenerInterface * @var UrlShortenerInterface
*/ */
private $urlShortener; private $urlShortener;
/**
* @var TranslatorInterface
*/
private $translator;
/** /**
* @var array * @var array
*/ */
@@ -37,13 +32,11 @@ class ResolveShortUrlAction extends AbstractRestAction
public function __construct( public function __construct(
UrlShortenerInterface $urlShortener, UrlShortenerInterface $urlShortener,
TranslatorInterface $translator,
array $domainConfig, array $domainConfig,
LoggerInterface $logger = null LoggerInterface $logger = null
) { ) {
parent::__construct($logger); parent::__construct($logger);
$this->urlShortener = $urlShortener; $this->urlShortener = $urlShortener;
$this->translator = $translator;
$this->domainConfig = $domainConfig; $this->domainConfig = $domainConfig;
} }
@@ -64,22 +57,19 @@ class ResolveShortUrlAction extends AbstractRestAction
$this->logger->warning('Provided short code with invalid format. {e}', ['e' => $e]); $this->logger->warning('Provided short code with invalid format. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => sprintf( 'message' => sprintf('Provided short code "%s" has an invalid format', $shortCode),
$this->translator->translate('Provided short code "%s" has an invalid format'),
$shortCode
),
], self::STATUS_BAD_REQUEST); ], self::STATUS_BAD_REQUEST);
} catch (EntityDoesNotExistException $e) { } catch (EntityDoesNotExistException $e) {
$this->logger->warning('Provided short code couldn\'t be found. {e}', ['e' => $e]); $this->logger->warning('Provided short code couldn\'t be found. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_ARGUMENT_ERROR, 'error' => RestUtils::INVALID_ARGUMENT_ERROR,
'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), 'message' => sprintf('No URL found for short code "%s"', $shortCode),
], self::STATUS_NOT_FOUND); ], self::STATUS_NOT_FOUND);
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->error('Unexpected error while resolving the URL behind a short code. {e}', ['e' => $e]); $this->logger->error('Unexpected error while resolving the URL behind a short code. {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::UNKNOWN_ERROR, 'error' => RestUtils::UNKNOWN_ERROR,
'message' => $this->translator->translate('Unexpected error occurred'), 'message' => 'Unexpected error occurred',
], self::STATUS_INTERNAL_SERVER_ERROR); ], self::STATUS_INTERNAL_SERVER_ERROR);
} }
} }

View File

@@ -10,7 +10,6 @@ use Shlinkio\Shlink\Core\Model\CreateShortUrlData;
use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
use Zend\I18n\Translator\TranslatorInterface;
class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction
{ {
@@ -24,12 +23,11 @@ class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction
public function __construct( public function __construct(
UrlShortenerInterface $urlShortener, UrlShortenerInterface $urlShortener,
TranslatorInterface $translator,
ApiKeyServiceInterface $apiKeyService, ApiKeyServiceInterface $apiKeyService,
array $domainConfig, array $domainConfig,
LoggerInterface $logger = null LoggerInterface $logger = null
) { ) {
parent::__construct($urlShortener, $translator, $domainConfig, $logger); parent::__construct($urlShortener, $domainConfig, $logger);
$this->apiKeyService = $apiKeyService; $this->apiKeyService = $apiKeyService;
} }
@@ -44,13 +42,11 @@ class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction
$query = $request->getQueryParams(); $query = $request->getQueryParams();
if (! $this->apiKeyService->check($query['apiKey'] ?? '')) { if (! $this->apiKeyService->check($query['apiKey'] ?? '')) {
throw new InvalidArgumentException( throw new InvalidArgumentException('No API key was provided or it is not valid');
$this->translator->translate('No API key was provided or it is not valid')
);
} }
if (! isset($query['longUrl'])) { if (! isset($query['longUrl'])) {
throw new InvalidArgumentException($this->translator->translate('A URL was not provided')); throw new InvalidArgumentException('A URL was not provided');
} }
return new CreateShortUrlData(new Uri($query['longUrl'])); return new CreateShortUrlData(new Uri($query['longUrl']));

View File

@@ -12,7 +12,6 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\EmptyResponse; use Zend\Diactoros\Response\EmptyResponse;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
use function sprintf; use function sprintf;
class UpdateTagAction extends AbstractRestAction class UpdateTagAction extends AbstractRestAction
@@ -24,19 +23,11 @@ class UpdateTagAction extends AbstractRestAction
* @var TagServiceInterface * @var TagServiceInterface
*/ */
private $tagService; private $tagService;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct( public function __construct(TagServiceInterface $tagService, LoggerInterface $logger = null)
TagServiceInterface $tagService, {
TranslatorInterface $translator,
LoggerInterface $logger = null
) {
parent::__construct($logger); parent::__construct($logger);
$this->tagService = $tagService; $this->tagService = $tagService;
$this->translator = $translator;
} }
/** /**
@@ -54,9 +45,8 @@ class UpdateTagAction extends AbstractRestAction
if (! isset($body['oldName'], $body['newName'])) { if (! isset($body['oldName'], $body['newName'])) {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::INVALID_ARGUMENT_ERROR, 'error' => RestUtils::INVALID_ARGUMENT_ERROR,
'message' => $this->translator->translate( 'message' =>
'You have to provide both \'oldName\' and \'newName\' params in order to properly rename the tag' 'You have to provide both \'oldName\' and \'newName\' params in order to properly rename the tag',
),
], self::STATUS_BAD_REQUEST); ], self::STATUS_BAD_REQUEST);
} }
@@ -66,10 +56,7 @@ class UpdateTagAction extends AbstractRestAction
} catch (EntityDoesNotExistException $e) { } catch (EntityDoesNotExistException $e) {
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::NOT_FOUND_ERROR, 'error' => RestUtils::NOT_FOUND_ERROR,
'message' => sprintf( 'message' => sprintf('It was not possible to find a tag with name %s', $body['oldName']),
$this->translator->translate('It wasn\'t possible to find a tag with name \'%s\''),
$body['oldName']
),
], self::STATUS_NOT_FOUND); ], self::STATUS_NOT_FOUND);
} }
} }

View File

@@ -14,7 +14,6 @@ use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\I18n\Translator\TranslatorInterface;
use function sprintf; use function sprintf;
class GetVisitsAction extends AbstractRestAction class GetVisitsAction extends AbstractRestAction
@@ -26,19 +25,11 @@ class GetVisitsAction extends AbstractRestAction
* @var VisitsTrackerInterface * @var VisitsTrackerInterface
*/ */
private $visitsTracker; private $visitsTracker;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct( public function __construct(VisitsTrackerInterface $visitsTracker, LoggerInterface $logger = null)
VisitsTrackerInterface $visitsTracker, {
TranslatorInterface $translator,
LoggerInterface $logger = null
) {
parent::__construct($logger); parent::__construct($logger);
$this->visitsTracker = $visitsTracker; $this->visitsTracker = $visitsTracker;
$this->translator = $translator;
} }
/** /**
@@ -64,16 +55,13 @@ class GetVisitsAction extends AbstractRestAction
$this->logger->warning('Provided nonexistent short code {e}', ['e' => $e]); $this->logger->warning('Provided nonexistent short code {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::getRestErrorCodeFromException($e), 'error' => RestUtils::getRestErrorCodeFromException($e),
'message' => sprintf( 'message' => sprintf('Provided short code %s does not exist', $shortCode),
$this->translator->translate('Provided short code %s does not exist'),
$shortCode
),
], self::STATUS_NOT_FOUND); ], self::STATUS_NOT_FOUND);
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->error('Unexpected error while parsing short code {e}', ['e' => $e]); $this->logger->error('Unexpected error while parsing short code {e}', ['e' => $e]);
return new JsonResponse([ return new JsonResponse([
'error' => RestUtils::UNKNOWN_ERROR, 'error' => RestUtils::UNKNOWN_ERROR,
'message' => $this->translator->translate('Unexpected error occurred'), 'message' => 'Unexpected error occurred',
], self::STATUS_INTERNAL_SERVER_ERROR); ], self::STATUS_INTERNAL_SERVER_ERROR);
} }
} }

View File

@@ -8,7 +8,6 @@ use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\I18n\Translator\TranslatorInterface;
class ApiKeyHeaderPlugin implements AuthenticationPluginInterface class ApiKeyHeaderPlugin implements AuthenticationPluginInterface
{ {
@@ -18,15 +17,10 @@ class ApiKeyHeaderPlugin implements AuthenticationPluginInterface
* @var ApiKeyServiceInterface * @var ApiKeyServiceInterface
*/ */
private $apiKeyService; private $apiKeyService;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct(ApiKeyServiceInterface $apiKeyService, TranslatorInterface $translator) public function __construct(ApiKeyServiceInterface $apiKeyService)
{ {
$this->apiKeyService = $apiKeyService; $this->apiKeyService = $apiKeyService;
$this->translator = $translator;
} }
/** /**
@@ -41,7 +35,7 @@ class ApiKeyHeaderPlugin implements AuthenticationPluginInterface
throw VerifyAuthenticationException::withError( throw VerifyAuthenticationException::withError(
RestUtils::INVALID_API_KEY_ERROR, RestUtils::INVALID_API_KEY_ERROR,
$this->translator->translate('Provided API key does not exist or is invalid.') 'Provided API key does not exist or is invalid.'
); );
} }

View File

@@ -9,7 +9,6 @@ use Shlinkio\Shlink\Rest\Authentication\JWTServiceInterface;
use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Throwable; use Throwable;
use Zend\I18n\Translator\TranslatorInterface;
use function count; use function count;
use function explode; use function explode;
use function sprintf; use function sprintf;
@@ -23,15 +22,10 @@ class AuthorizationHeaderPlugin implements AuthenticationPluginInterface
* @var JWTServiceInterface * @var JWTServiceInterface
*/ */
private $jwtService; private $jwtService;
/**
* @var TranslatorInterface
*/
private $translator;
public function __construct(JWTServiceInterface $jwtService, TranslatorInterface $translator) public function __construct(JWTServiceInterface $jwtService)
{ {
$this->jwtService = $jwtService; $this->jwtService = $jwtService;
$this->translator = $translator;
} }
/** /**
@@ -45,10 +39,7 @@ class AuthorizationHeaderPlugin implements AuthenticationPluginInterface
if (count($authTokenParts) === 1) { if (count($authTokenParts) === 1) {
throw VerifyAuthenticationException::withError( throw VerifyAuthenticationException::withError(
RestUtils::INVALID_AUTHORIZATION_ERROR, RestUtils::INVALID_AUTHORIZATION_ERROR,
sprintf( sprintf('You need to provide the Bearer type in the %s header.', self::HEADER_NAME)
$this->translator->translate('You need to provide the Bearer type in the %s header.'),
self::HEADER_NAME
)
); );
} }
@@ -57,9 +48,7 @@ class AuthorizationHeaderPlugin implements AuthenticationPluginInterface
if (strtolower($authType) !== 'bearer') { if (strtolower($authType) !== 'bearer') {
throw VerifyAuthenticationException::withError( throw VerifyAuthenticationException::withError(
RestUtils::INVALID_AUTHORIZATION_ERROR, RestUtils::INVALID_AUTHORIZATION_ERROR,
sprintf($this->translator->translate( sprintf('Provided authorization type %s is not supported. Use Bearer instead.', $authType)
'Provided authorization type %s is not supported. Use Bearer instead.'
), $authType)
); );
} }
@@ -76,10 +65,11 @@ class AuthorizationHeaderPlugin implements AuthenticationPluginInterface
{ {
return VerifyAuthenticationException::withError( return VerifyAuthenticationException::withError(
RestUtils::INVALID_AUTH_TOKEN_ERROR, RestUtils::INVALID_AUTH_TOKEN_ERROR,
sprintf($this->translator->translate( sprintf(
'Missing or invalid auth token provided. Perform a new authentication request and send provided ' 'Missing or invalid auth token provided. Perform a new authentication request and send provided '
. 'token on every new request on the %s header' . 'token on every new request on the %s header',
), self::HEADER_NAME), self::HEADER_NAME
),
$prev $prev
); );
} }

View File

@@ -19,17 +19,12 @@ use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Expressive\Router\RouteResult; use Zend\Expressive\Router\RouteResult;
use Zend\I18n\Translator\TranslatorInterface;
use function Functional\contains; use function Functional\contains;
use function implode; use function implode;
use function sprintf; use function sprintf;
class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterface, RequestMethodInterface class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterface, RequestMethodInterface
{ {
/**
* @var TranslatorInterface
*/
private $translator;
/** /**
* @var LoggerInterface * @var LoggerInterface
*/ */
@@ -45,14 +40,12 @@ class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterfa
public function __construct( public function __construct(
RequestToHttpAuthPluginInterface $requestToAuthPlugin, RequestToHttpAuthPluginInterface $requestToAuthPlugin,
TranslatorInterface $translator,
array $routesWhitelist, array $routesWhitelist,
LoggerInterface $logger = null LoggerInterface $logger = null
) { ) {
$this->translator = $translator;
$this->routesWhitelist = $routesWhitelist; $this->routesWhitelist = $routesWhitelist;
$this->logger = $logger ?: new NullLogger();
$this->requestToAuthPlugin = $requestToAuthPlugin; $this->requestToAuthPlugin = $requestToAuthPlugin;
$this->logger = $logger ?: new NullLogger();
} }
/** /**
@@ -81,9 +74,10 @@ class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterfa
$plugin = $this->requestToAuthPlugin->fromRequest($request); $plugin = $this->requestToAuthPlugin->fromRequest($request);
} catch (ContainerExceptionInterface | NoAuthenticationException $e) { } catch (ContainerExceptionInterface | NoAuthenticationException $e) {
$this->logger->warning('Invalid or no authentication provided. {e}', ['e' => $e]); $this->logger->warning('Invalid or no authentication provided. {e}', ['e' => $e]);
return $this->createErrorResponse(sprintf($this->translator->translate( return $this->createErrorResponse(sprintf(
'Expected one of the following authentication headers, but none were provided, ["%s"]' 'Expected one of the following authentication headers, but none were provided, ["%s"]',
), implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS))); implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS)
));
} }
try { try {

View File

@@ -11,7 +11,6 @@ use Shlinkio\Shlink\Rest\Authentication\JWTService;
use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Entity\ApiKey;
use Shlinkio\Shlink\Rest\Service\ApiKeyService; use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
use function strpos; use function strpos;
class AuthenticateActionTest extends TestCase class AuthenticateActionTest extends TestCase
@@ -35,11 +34,7 @@ class AuthenticateActionTest extends TestCase
$this->jwtService = $this->prophesize(JWTService::class); $this->jwtService = $this->prophesize(JWTService::class);
$this->jwtService->create(Argument::cetera())->willReturn(''); $this->jwtService->create(Argument::cetera())->willReturn('');
$this->action = new AuthenticateAction( $this->action = new AuthenticateAction($this->apiKeyService->reveal(), $this->jwtService->reveal());
$this->apiKeyService->reveal(),
$this->jwtService->reveal(),
Translator::factory([])
);
} }
/** /**

View File

@@ -15,7 +15,6 @@ use Shlinkio\Shlink\Rest\Action\ShortUrl\CreateShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
use Zend\I18n\Translator\Translator;
use function strpos; use function strpos;
class CreateShortUrlActionTest extends TestCase class CreateShortUrlActionTest extends TestCase
@@ -32,7 +31,7 @@ class CreateShortUrlActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->urlShortener = $this->prophesize(UrlShortener::class); $this->urlShortener = $this->prophesize(UrlShortener::class);
$this->action = new CreateShortUrlAction($this->urlShortener->reveal(), Translator::factory([]), [ $this->action = new CreateShortUrlAction($this->urlShortener->reveal(), [
'schema' => 'http', 'schema' => 'http',
'hostname' => 'foo.com', 'hostname' => 'foo.com',
]); ]);

View File

@@ -13,7 +13,6 @@ use Shlinkio\Shlink\Rest\Util\RestUtils;
use Throwable; use Throwable;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class DeleteShortUrlActionTest extends TestCase class DeleteShortUrlActionTest extends TestCase
{ {
@@ -29,7 +28,7 @@ class DeleteShortUrlActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->service = $this->prophesize(DeleteShortUrlServiceInterface::class); $this->service = $this->prophesize(DeleteShortUrlServiceInterface::class);
$this->action = new DeleteShortUrlAction($this->service->reveal(), Translator::factory([])); $this->action = new DeleteShortUrlAction($this->service->reveal());
} }
/** /**

View File

@@ -13,7 +13,6 @@ use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class EditShortUrlActionTest extends TestCase class EditShortUrlActionTest extends TestCase
{ {
@@ -29,7 +28,7 @@ class EditShortUrlActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class); $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class);
$this->action = new EditShortUrlAction($this->shortUrlService->reveal(), Translator::factory([])); $this->action = new EditShortUrlAction($this->shortUrlService->reveal());
} }
/** /**

View File

@@ -10,7 +10,6 @@ use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlTagsAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlTagsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class EditShortUrlTagsActionTest extends TestCase class EditShortUrlTagsActionTest extends TestCase
{ {
@@ -26,7 +25,7 @@ class EditShortUrlTagsActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->shortUrlService = $this->prophesize(ShortUrlService::class); $this->shortUrlService = $this->prophesize(ShortUrlService::class);
$this->action = new EditShortUrlTagsAction($this->shortUrlService->reveal(), Translator::factory([])); $this->action = new EditShortUrlTagsAction($this->shortUrlService->reveal());
} }
/** /**

View File

@@ -9,7 +9,6 @@ use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
use Zend\Paginator\Adapter\ArrayAdapter; use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Paginator; use Zend\Paginator\Paginator;
@@ -27,7 +26,7 @@ class ListShortUrlsActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->service = $this->prophesize(ShortUrlService::class); $this->service = $this->prophesize(ShortUrlService::class);
$this->action = new ListShortUrlsAction($this->service->reveal(), Translator::factory([]), [ $this->action = new ListShortUrlsAction($this->service->reveal(), [
'hostname' => 'doma.in', 'hostname' => 'doma.in',
'schema' => 'https', 'schema' => 'https',
]); ]);

View File

@@ -13,7 +13,6 @@ use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\ShortUrl\ResolveShortUrlAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\ResolveShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
use function strpos; use function strpos;
class ResolveShortUrlActionTest extends TestCase class ResolveShortUrlActionTest extends TestCase
@@ -30,7 +29,7 @@ class ResolveShortUrlActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->urlShortener = $this->prophesize(UrlShortener::class); $this->urlShortener = $this->prophesize(UrlShortener::class);
$this->action = new ResolveShortUrlAction($this->urlShortener->reveal(), Translator::factory([]), []); $this->action = new ResolveShortUrlAction($this->urlShortener->reveal(), []);
} }
/** /**

View File

@@ -14,7 +14,6 @@ use Shlinkio\Shlink\Rest\Action\ShortUrl\SingleStepCreateShortUrlAction;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class SingleStepCreateShortUrlActionTest extends TestCase class SingleStepCreateShortUrlActionTest extends TestCase
{ {
@@ -38,7 +37,6 @@ class SingleStepCreateShortUrlActionTest extends TestCase
$this->action = new SingleStepCreateShortUrlAction( $this->action = new SingleStepCreateShortUrlAction(
$this->urlShortener->reveal(), $this->urlShortener->reveal(),
Translator::factory([]),
$this->apiKeyService->reveal(), $this->apiKeyService->reveal(),
[ [
'schema' => 'http', 'schema' => 'http',

View File

@@ -11,7 +11,6 @@ use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\UpdateTagAction; use Shlinkio\Shlink\Rest\Action\Tag\UpdateTagAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class UpdateTagActionTest extends TestCase class UpdateTagActionTest extends TestCase
{ {
@@ -27,7 +26,7 @@ class UpdateTagActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->tagService = $this->prophesize(TagServiceInterface::class); $this->tagService = $this->prophesize(TagServiceInterface::class);
$this->action = new UpdateTagAction($this->tagService->reveal(), Translator::factory([])); $this->action = new UpdateTagAction($this->tagService->reveal());
} }
/** /**

View File

@@ -13,7 +13,6 @@ use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Core\Service\VisitsTracker;
use Shlinkio\Shlink\Rest\Action\Visit\GetVisitsAction; use Shlinkio\Shlink\Rest\Action\Visit\GetVisitsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class GetVisitsActionTest extends TestCase class GetVisitsActionTest extends TestCase
{ {
@@ -29,7 +28,7 @@ class GetVisitsActionTest extends TestCase
public function setUp() public function setUp()
{ {
$this->visitsTracker = $this->prophesize(VisitsTracker::class); $this->visitsTracker = $this->prophesize(VisitsTracker::class);
$this->action = new GetVisitsAction($this->visitsTracker->reveal(), Translator::factory([])); $this->action = new GetVisitsAction($this->visitsTracker->reveal());
} }
/** /**

View File

@@ -11,7 +11,6 @@ use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class ApiKeyHeaderPluginTest extends TestCase class ApiKeyHeaderPluginTest extends TestCase
{ {
@@ -27,7 +26,7 @@ class ApiKeyHeaderPluginTest extends TestCase
public function setUp() public function setUp()
{ {
$this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class);
$this->plugin = new ApiKeyHeaderPlugin($this->apiKeyService->reveal(), Translator::factory([])); $this->plugin = new ApiKeyHeaderPlugin($this->apiKeyService->reveal());
} }
/** /**

View File

@@ -10,7 +10,6 @@ use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthorizationHeaderPlugin;
use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
use function sprintf; use function sprintf;
class AuthorizationHeaderPluginTest extends TestCase class AuthorizationHeaderPluginTest extends TestCase
@@ -27,7 +26,7 @@ class AuthorizationHeaderPluginTest extends TestCase
public function setUp() public function setUp()
{ {
$this->jwtService = $this->prophesize(JWTServiceInterface::class); $this->jwtService = $this->prophesize(JWTServiceInterface::class);
$this->plugin = new AuthorizationHeaderPlugin($this->jwtService->reveal(), Translator::factory([])); $this->plugin = new AuthorizationHeaderPlugin($this->jwtService->reveal());
} }
/** /**

View File

@@ -28,6 +28,5 @@ class ConfigProviderTest extends TestCase
$this->assertArrayHasKey('error_handler', $config); $this->assertArrayHasKey('error_handler', $config);
$this->assertArrayHasKey('routes', $config); $this->assertArrayHasKey('routes', $config);
$this->assertArrayHasKey('dependencies', $config); $this->assertArrayHasKey('dependencies', $config);
$this->assertArrayHasKey('translator', $config);
} }
} }

View File

@@ -25,7 +25,6 @@ use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\Expressive\Router\Route; use Zend\Expressive\Router\Route;
use Zend\Expressive\Router\RouteResult; use Zend\Expressive\Router\RouteResult;
use Zend\I18n\Translator\Translator;
use function implode; use function implode;
use function sprintf; use function sprintf;
use function Zend\Stratigility\middleware; use function Zend\Stratigility\middleware;
@@ -49,9 +48,7 @@ class AuthenticationMiddlewareTest extends TestCase
public function setUp() public function setUp()
{ {
$this->requestToPlugin = $this->prophesize(RequestToHttpAuthPluginInterface::class); $this->requestToPlugin = $this->prophesize(RequestToHttpAuthPluginInterface::class);
$this->middleware = new AuthenticationMiddleware($this->requestToPlugin->reveal(), Translator::factory([]), [ $this->middleware = new AuthenticationMiddleware($this->requestToPlugin->reveal(), [AuthenticateAction::class]);
AuthenticateAction::class,
]);
} }
/** /**