Remove dependencies on url_shortener raw config

This commit is contained in:
Alejandro Celaya
2024-10-20 12:52:00 +02:00
parent b991b1699e
commit c8e5196aab
26 changed files with 83 additions and 84 deletions

View File

@@ -8,6 +8,7 @@ use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtils;
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
use Shlinkio\Shlink\Core\Visit\Model\VisitsParams;
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
@@ -20,7 +21,7 @@ class DomainVisitsAction extends AbstractRestAction
public function __construct(
private readonly VisitsStatsHelperInterface $visitsHelper,
private readonly string $defaultDomain,
private readonly UrlShortenerOptions $urlShortenerOptions,
) {
}
@@ -37,7 +38,7 @@ class DomainVisitsAction extends AbstractRestAction
private function resolveDomainParam(Request $request): string
{
$domainParam = $request->getAttribute('domain', '');
if ($domainParam === $this->defaultDomain) {
if ($domainParam === $this->urlShortenerOptions->defaultDomain()) {
return 'DEFAULT';
}

View File

@@ -8,11 +8,12 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
class DefaultShortCodesLengthMiddleware implements MiddlewareInterface
readonly class DefaultShortCodesLengthMiddleware implements MiddlewareInterface
{
public function __construct(private int $defaultShortCodesLength)
public function __construct(private UrlShortenerOptions $urlShortenerOptions)
{
}
@@ -21,7 +22,7 @@ class DefaultShortCodesLengthMiddleware implements MiddlewareInterface
/** @var array $body */
$body = $request->getParsedBody();
if (! isset($body[ShortUrlInputFilter::SHORT_CODE_LENGTH])) {
$body[ShortUrlInputFilter::SHORT_CODE_LENGTH] = $this->defaultShortCodesLength;
$body[ShortUrlInputFilter::SHORT_CODE_LENGTH] = $this->urlShortenerOptions->defaultShortCodesLength;
}
return $handler->handle($request->withParsedBody($body));

View File

@@ -8,10 +8,11 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
class DropDefaultDomainFromRequestMiddleware implements MiddlewareInterface
readonly class DropDefaultDomainFromRequestMiddleware implements MiddlewareInterface
{
public function __construct(private readonly string $defaultDomain)
public function __construct(private UrlShortenerOptions $urlShortenerOptions)
{
}
@@ -27,7 +28,7 @@ class DropDefaultDomainFromRequestMiddleware implements MiddlewareInterface
private function sanitizeDomainFromPayload(array $payload): array
{
if (isset($payload['domain']) && $payload['domain'] === $this->defaultDomain) {
if (isset($payload['domain']) && $payload['domain'] === $this->urlShortenerOptions->defaultDomain()) {
unset($payload['domain']);
}