mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-03 12:46:59 -06:00
Removed hardcoded route names for core routes and used action class names instead
This commit is contained in:
parent
eeb5306883
commit
01f60614ef
@ -11,7 +11,7 @@ return [
|
|||||||
|
|
||||||
'routes' => [
|
'routes' => [
|
||||||
[
|
[
|
||||||
'name' => 'long-url-redirect',
|
'name' => Action\RedirectAction::class,
|
||||||
'path' => '/{shortCode}',
|
'path' => '/{shortCode}',
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
IpAddress::class,
|
IpAddress::class,
|
||||||
@ -20,7 +20,7 @@ return [
|
|||||||
'allowed_methods' => [RequestMethod::METHOD_GET],
|
'allowed_methods' => [RequestMethod::METHOD_GET],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'pixel-tracking',
|
'name' => Action\PixelAction::class,
|
||||||
'path' => '/{shortCode}/track',
|
'path' => '/{shortCode}/track',
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
IpAddress::class,
|
IpAddress::class,
|
||||||
@ -29,7 +29,7 @@ return [
|
|||||||
'allowed_methods' => [RequestMethod::METHOD_GET],
|
'allowed_methods' => [RequestMethod::METHOD_GET],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'short-url-qr-code',
|
'name' => Action\QrCodeAction::class,
|
||||||
'path' => '/{shortCode}/qr-code[/{size:[0-9]+}]',
|
'path' => '/{shortCode}/qr-code[/{size:[0-9]+}]',
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
Middleware\QrCodeCacheMiddleware::class,
|
Middleware\QrCodeCacheMiddleware::class,
|
||||||
|
@ -68,7 +68,7 @@ class QrCodeAction implements MiddlewareInterface
|
|||||||
return $this->buildErrorResponse($request, $handler);
|
return $this->buildErrorResponse($request, $handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $this->router->generateUri('long-url-redirect', ['shortCode' => $shortCode]);
|
$path = $this->router->generateUri(RedirectAction::class, ['shortCode' => $shortCode]);
|
||||||
$size = $this->getSizeParam($request);
|
$size = $this->getSizeParam($request);
|
||||||
|
|
||||||
$qrCode = new QrCode((string) $request->getUri()->withPath($path)->withQuery(''));
|
$qrCode = new QrCode((string) $request->getUri()->withPath($path)->withQuery(''));
|
||||||
|
@ -9,6 +9,7 @@ use InvalidArgumentException;
|
|||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
use Shlinkio\Shlink\Core\Action\RedirectAction;
|
||||||
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
||||||
use Zend\Diactoros\Response;
|
use Zend\Diactoros\Response;
|
||||||
use Zend\Expressive\Router\RouteResult;
|
use Zend\Expressive\Router\RouteResult;
|
||||||
@ -91,7 +92,7 @@ class NotFoundHandler implements RequestHandlerInterface
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
$routeResult->isSuccess() &&
|
$routeResult->isSuccess() &&
|
||||||
$routeResult->getMatchedRouteName() === 'long-url-redirect' &&
|
$routeResult->getMatchedRouteName() === RedirectAction::class &&
|
||||||
$this->redirectOptions->hasInvalidShortUrlRedirect()
|
$this->redirectOptions->hasInvalidShortUrlRedirect()
|
||||||
) {
|
) {
|
||||||
return new Response\RedirectResponse($this->redirectOptions->getInvalidShortUrlRedirect());
|
return new Response\RedirectResponse($this->redirectOptions->getInvalidShortUrlRedirect());
|
||||||
|
@ -9,6 +9,7 @@ use Prophecy\Argument;
|
|||||||
use Prophecy\Prophecy\ObjectProphecy;
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
use Shlinkio\Shlink\Core\Action\RedirectAction;
|
||||||
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
||||||
use Shlinkio\Shlink\Core\Response\NotFoundHandler;
|
use Shlinkio\Shlink\Core\Response\NotFoundHandler;
|
||||||
use Zend\Diactoros\Response;
|
use Zend\Diactoros\Response;
|
||||||
@ -101,7 +102,7 @@ class NotFoundHandlerTest extends TestCase
|
|||||||
'',
|
'',
|
||||||
$this->prophesize(MiddlewareInterface::class)->reveal(),
|
$this->prophesize(MiddlewareInterface::class)->reveal(),
|
||||||
['GET'],
|
['GET'],
|
||||||
'long-url-redirect'
|
RedirectAction::class
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user