Moved some config to the proper namespace, now that config is no longer part of the public contract

This commit is contained in:
Alejandro Celaya
2022-01-16 15:34:07 +01:00
parent fb43885d85
commit bfb54189b8
9 changed files with 63 additions and 52 deletions

View 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;
}
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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)
{
}