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,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));