mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Core\Options;
|
|
|
|
use Laminas\Stdlib\AbstractOptions;
|
|
|
|
use function Functional\contains;
|
|
|
|
use const Shlinkio\Shlink\Core\DEFAULT_REDIRECT_CACHE_LIFETIME;
|
|
use const Shlinkio\Shlink\Core\DEFAULT_REDIRECT_STATUS_CODE;
|
|
|
|
class UrlShortenerOptions extends AbstractOptions
|
|
{
|
|
protected $__strictMode__ = false; // phpcs:ignore
|
|
|
|
private bool $validateUrl = true;
|
|
private int $redirectStatusCode = DEFAULT_REDIRECT_STATUS_CODE;
|
|
private int $redirectCacheLifetime = DEFAULT_REDIRECT_CACHE_LIFETIME;
|
|
|
|
public function isUrlValidationEnabled(): bool
|
|
{
|
|
return $this->validateUrl;
|
|
}
|
|
|
|
protected function setValidateUrl(bool $validateUrl): void
|
|
{
|
|
$this->validateUrl = $validateUrl;
|
|
}
|
|
|
|
public function redirectStatusCode(): int
|
|
{
|
|
return $this->redirectStatusCode;
|
|
}
|
|
|
|
protected function setRedirectStatusCode(int $redirectStatusCode): void
|
|
{
|
|
$this->redirectStatusCode = $this->normalizeRedirectStatusCode($redirectStatusCode);
|
|
}
|
|
|
|
private function normalizeRedirectStatusCode(int $statusCode): int
|
|
{
|
|
return contains([301, 302], $statusCode) ? $statusCode : DEFAULT_REDIRECT_STATUS_CODE;
|
|
}
|
|
|
|
public function redirectCacheLifetime(): int
|
|
{
|
|
return $this->redirectCacheLifetime;
|
|
}
|
|
|
|
protected function setRedirectCacheLifetime(int $redirectCacheLifetime): void
|
|
{
|
|
$this->redirectCacheLifetime = $redirectCacheLifetime > 0
|
|
? $redirectCacheLifetime
|
|
: DEFAULT_REDIRECT_CACHE_LIFETIME;
|
|
}
|
|
}
|