mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
#867 Small refactoring on NotFoundRedirecthandler
This commit is contained in:
parent
4dbcf6857e
commit
deeca582db
1 changed files with 10 additions and 8 deletions
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shlinkio\Shlink\Core\ErrorHandler;
|
||||
|
||||
use Laminas\Diactoros\Response;
|
||||
use Laminas\Diactoros\Response\RedirectResponse;
|
||||
use Mezzio\Router\RouteResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
@ -12,17 +12,19 @@ use Psr\Http\Message\UriInterface;
|
|||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Shlinkio\Shlink\Core\Action\RedirectAction;
|
||||
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
||||
use Shlinkio\Shlink\Core\Options;
|
||||
|
||||
use function rtrim;
|
||||
|
||||
class NotFoundRedirectHandler implements MiddlewareInterface
|
||||
{
|
||||
private NotFoundRedirectOptions $redirectOptions;
|
||||
private Options\NotFoundRedirectOptions $redirectOptions;
|
||||
private string $shlinkBasePath;
|
||||
|
||||
public function __construct(NotFoundRedirectOptions $redirectOptions, string $shlinkBasePath)
|
||||
{
|
||||
public function __construct(
|
||||
Options\NotFoundRedirectOptions $redirectOptions,
|
||||
string $shlinkBasePath
|
||||
) {
|
||||
$this->redirectOptions = $redirectOptions;
|
||||
$this->shlinkBasePath = $shlinkBasePath;
|
||||
}
|
||||
|
@ -41,11 +43,11 @@ class NotFoundRedirectHandler implements MiddlewareInterface
|
|||
$isBaseUrl = rtrim($uri->getPath(), '/') === $this->shlinkBasePath;
|
||||
|
||||
if ($isBaseUrl && $this->redirectOptions->hasBaseUrlRedirect()) {
|
||||
return new Response\RedirectResponse($this->redirectOptions->getBaseUrlRedirect());
|
||||
return new RedirectResponse($this->redirectOptions->getBaseUrlRedirect());
|
||||
}
|
||||
|
||||
if (!$isBaseUrl && $routeResult->isFailure() && $this->redirectOptions->hasRegular404Redirect()) {
|
||||
return new Response\RedirectResponse($this->redirectOptions->getRegular404Redirect());
|
||||
return new RedirectResponse($this->redirectOptions->getRegular404Redirect());
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -53,7 +55,7 @@ class NotFoundRedirectHandler implements MiddlewareInterface
|
|||
$routeResult->getMatchedRouteName() === RedirectAction::class &&
|
||||
$this->redirectOptions->hasInvalidShortUrlRedirect()
|
||||
) {
|
||||
return new Response\RedirectResponse($this->redirectOptions->getInvalidShortUrlRedirect());
|
||||
return new RedirectResponse($this->redirectOptions->getInvalidShortUrlRedirect());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue