mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Moved some config to the proper namespace, now that config is no longer part of the public contract
This commit is contained in:
45
module/Core/src/Options/RedirectOptions.php
Normal file
45
module/Core/src/Options/RedirectOptions.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Options;
|
||||
|
||||
use Laminas\Stdlib\AbstractOptions;
|
||||
|
||||
use function Functional\contains;
|
||||
|
||||
use const Shlinkio\Shlink\DEFAULT_REDIRECT_CACHE_LIFETIME;
|
||||
use const Shlinkio\Shlink\DEFAULT_REDIRECT_STATUS_CODE;
|
||||
|
||||
class RedirectOptions extends AbstractOptions
|
||||
{
|
||||
private int $redirectStatusCode = DEFAULT_REDIRECT_STATUS_CODE;
|
||||
private int $redirectCacheLifetime = DEFAULT_REDIRECT_CACHE_LIFETIME;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -6,18 +6,11 @@ namespace Shlinkio\Shlink\Core\Options;
|
||||
|
||||
use Laminas\Stdlib\AbstractOptions;
|
||||
|
||||
use function Functional\contains;
|
||||
|
||||
use const Shlinkio\Shlink\DEFAULT_REDIRECT_CACHE_LIFETIME;
|
||||
use const Shlinkio\Shlink\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;
|
||||
private bool $autoResolveTitles = false;
|
||||
private bool $appendExtraPath = false;
|
||||
|
||||
@@ -31,33 +24,6 @@ class UrlShortenerOptions extends AbstractOptions
|
||||
$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;
|
||||
}
|
||||
|
||||
public function autoResolveTitles(): bool
|
||||
{
|
||||
return $this->autoResolveTitles;
|
||||
|
||||
@@ -10,22 +10,22 @@ class WebhookOptions extends AbstractOptions
|
||||
{
|
||||
protected $__strictMode__ = false; // phpcs:ignore
|
||||
|
||||
private array $visitsWebhooks = [];
|
||||
private array $webhooks = [];
|
||||
private bool $notifyOrphanVisitsToWebhooks = false;
|
||||
|
||||
public function webhooks(): array
|
||||
{
|
||||
return $this->visitsWebhooks;
|
||||
return $this->webhooks;
|
||||
}
|
||||
|
||||
public function hasWebhooks(): bool
|
||||
{
|
||||
return ! empty($this->visitsWebhooks);
|
||||
return ! empty($this->webhooks);
|
||||
}
|
||||
|
||||
protected function setVisitsWebhooks(array $visitsWebhooks): void
|
||||
protected function setWebhooks(array $webhooks): void
|
||||
{
|
||||
$this->visitsWebhooks = $visitsWebhooks;
|
||||
$this->webhooks = $webhooks;
|
||||
}
|
||||
|
||||
public function notifyOrphanVisits(): bool
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace Shlinkio\Shlink\Core\Util;
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use Laminas\Diactoros\Response\RedirectResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Shlinkio\Shlink\Core\Options\UrlShortenerOptions;
|
||||
use Shlinkio\Shlink\Core\Options\RedirectOptions;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class RedirectResponseHelper implements RedirectResponseHelperInterface
|
||||
{
|
||||
public function __construct(private UrlShortenerOptions $options)
|
||||
public function __construct(private RedirectOptions $options)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user