mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-05 23:03:11 +08:00
29 lines
881 B
PHP
29 lines
881 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Rest\Middleware\ShortUrl;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Server\MiddlewareInterface;
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
use Shlinkio\Shlink\Core\Validation\ShortUrlInputFilter;
|
|
|
|
class DefaultShortCodesLengthMiddleware implements MiddlewareInterface
|
|
{
|
|
public function __construct(private int $defaultShortCodesLength)
|
|
{
|
|
}
|
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
|
{
|
|
$body = $request->getParsedBody();
|
|
if (! isset($body[ShortUrlInputFilter::SHORT_CODE_LENGTH])) {
|
|
$body[ShortUrlInputFilter::SHORT_CODE_LENGTH] = $this->defaultShortCodesLength;
|
|
}
|
|
|
|
return $handler->handle($request->withParsedBody($body));
|
|
}
|
|
}
|