mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 15:59:56 +03:00
Move allowed HTTP methods definition to RedirectStatus enum
This commit is contained in:
parent
c57494d7cd
commit
13ee71f351
2 changed files with 11 additions and 7 deletions
|
@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shlinkio\Shlink\Core\Config\PostProcessor;
|
namespace Shlinkio\Shlink\Core\Config\PostProcessor;
|
||||||
|
|
||||||
use Fig\Http\Message\RequestMethodInterface;
|
|
||||||
use Mezzio\Router\Route;
|
|
||||||
use Shlinkio\Shlink\Core\Action\RedirectAction;
|
use Shlinkio\Shlink\Core\Action\RedirectAction;
|
||||||
use Shlinkio\Shlink\Core\Util\RedirectStatus;
|
use Shlinkio\Shlink\Core\Util\RedirectStatus;
|
||||||
|
|
||||||
|
@ -40,9 +38,7 @@ class ShortUrlMethodsProcessor
|
||||||
$redirectStatus = RedirectStatus::tryFrom(
|
$redirectStatus = RedirectStatus::tryFrom(
|
||||||
$config['redirects']['redirect_status_code'] ?? 0,
|
$config['redirects']['redirect_status_code'] ?? 0,
|
||||||
) ?? DEFAULT_REDIRECT_STATUS_CODE;
|
) ?? DEFAULT_REDIRECT_STATUS_CODE;
|
||||||
$redirectRoute['allowed_methods'] = $redirectStatus->isGetOnlyStatus()
|
$redirectRoute['allowed_methods'] = $redirectStatus->allowedHttpMethods();
|
||||||
? [RequestMethodInterface::METHOD_GET]
|
|
||||||
: Route::HTTP_METHOD_ANY;
|
|
||||||
|
|
||||||
$config['routes'] = [...$rest, $redirectRoute];
|
$config['routes'] = [...$rest, $redirectRoute];
|
||||||
return $config;
|
return $config;
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
namespace Shlinkio\Shlink\Core\Util;
|
namespace Shlinkio\Shlink\Core\Util;
|
||||||
|
|
||||||
|
use Fig\Http\Message\RequestMethodInterface;
|
||||||
|
use Mezzio\Router\Route;
|
||||||
|
|
||||||
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
|
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
|
||||||
|
|
||||||
enum RedirectStatus: int
|
enum RedirectStatus: int
|
||||||
|
@ -16,8 +19,13 @@ enum RedirectStatus: int
|
||||||
return contains($this, [self::STATUS_301, self::STATUS_308]);
|
return contains($this, [self::STATUS_301, self::STATUS_308]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isGetOnlyStatus(): bool
|
/**
|
||||||
|
* @return array<RequestMethodInterface::METHOD_*>|Route::HTTP_METHOD_ANY
|
||||||
|
*/
|
||||||
|
public function allowedHttpMethods(): array|null
|
||||||
{
|
{
|
||||||
return contains($this, [self::STATUS_301, self::STATUS_302]);
|
return contains($this, [self::STATUS_301, self::STATUS_302])
|
||||||
|
? [RequestMethodInterface::METHOD_GET]
|
||||||
|
: Route::HTTP_METHOD_ANY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue