mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
Remove dependencies on url_shortener raw config
This commit is contained in:
@@ -86,7 +86,7 @@ return [
|
||||
Action\Visit\TagVisitsAction::class => [Visit\VisitsStatsHelper::class],
|
||||
Action\Visit\DomainVisitsAction::class => [
|
||||
Visit\VisitsStatsHelper::class,
|
||||
'config.url_shortener.domain.hostname',
|
||||
Config\Options\UrlShortenerOptions::class,
|
||||
],
|
||||
Action\Visit\GlobalVisitsAction::class => [Visit\VisitsStatsHelper::class],
|
||||
Action\Visit\OrphanVisitsAction::class => [Visit\VisitsStatsHelper::class],
|
||||
@@ -113,10 +113,10 @@ return [
|
||||
],
|
||||
|
||||
Middleware\CrossDomainMiddleware::class => ['config.cors'],
|
||||
Middleware\ShortUrl\DropDefaultDomainFromRequestMiddleware::class => ['config.url_shortener.domain.hostname'],
|
||||
Middleware\ShortUrl\DefaultShortCodesLengthMiddleware::class => [
|
||||
'config.url_shortener.default_short_codes_length',
|
||||
Middleware\ShortUrl\DropDefaultDomainFromRequestMiddleware::class => [
|
||||
Config\Options\UrlShortenerOptions::class,
|
||||
],
|
||||
Middleware\ShortUrl\DefaultShortCodesLengthMiddleware::class => [Config\Options\UrlShortenerOptions::class],
|
||||
Middleware\ShortUrl\OverrideDomainMiddleware::class => [DomainService::class],
|
||||
Middleware\Mercure\NotConfiguredMercureErrorHandler::class => [
|
||||
ProblemDetailsResponseFactory::class,
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class EditShortUrlActionTest extends TestCase
|
||||
{
|
||||
$this->shortUrlService = $this->createMock(ShortUrlServiceInterface::class);
|
||||
$this->action = new EditShortUrlAction($this->shortUrlService, new ShortUrlDataTransformer(
|
||||
new ShortUrlStringifier([]),
|
||||
new ShortUrlStringifier(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlListServiceInterface;
|
||||
@@ -30,10 +31,10 @@ class ListShortUrlsActionTest extends TestCase
|
||||
$this->service = $this->createMock(ShortUrlListServiceInterface::class);
|
||||
|
||||
$this->action = new ListShortUrlsAction($this->service, new ShortUrlDataTransformer(
|
||||
new ShortUrlStringifier([
|
||||
new ShortUrlStringifier(new UrlShortenerOptions(domain: [
|
||||
'hostname' => 's.test',
|
||||
'schema' => 'https',
|
||||
]),
|
||||
])),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class ResolveShortUrlActionTest extends TestCase
|
||||
{
|
||||
$this->urlResolver = $this->createMock(ShortUrlResolverInterface::class);
|
||||
$this->action = new ResolveShortUrlAction($this->urlResolver, new ShortUrlDataTransformer(
|
||||
new ShortUrlStringifier([]),
|
||||
new ShortUrlStringifier(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
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\Visit\DomainVisitsAction;
|
||||
@@ -24,7 +25,10 @@ class DomainVisitsActionTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->visitsHelper = $this->createMock(VisitsStatsHelperInterface::class);
|
||||
$this->action = new DomainVisitsAction($this->visitsHelper, 'the_default.com');
|
||||
$this->action = new DomainVisitsAction(
|
||||
$this->visitsHelper,
|
||||
new UrlShortenerOptions(domain: ['hostname' => 'the_default.com']),
|
||||
);
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideDomainAuthorities')]
|
||||
|
||||
@@ -13,6 +13,7 @@ use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
|
||||
use Shlinkio\Shlink\Rest\Middleware\ShortUrl\DefaultShortCodesLengthMiddleware;
|
||||
|
||||
@@ -24,7 +25,7 @@ class DefaultShortCodesLengthMiddlewareTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->handler = $this->createMock(RequestHandlerInterface::class);
|
||||
$this->middleware = new DefaultShortCodesLengthMiddleware(8);
|
||||
$this->middleware = new DefaultShortCodesLengthMiddleware(new UrlShortenerOptions(defaultShortCodesLength: 8));
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideBodies')]
|
||||
|
||||
@@ -13,6 +13,7 @@ use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
|
||||
use Shlinkio\Shlink\Rest\Middleware\ShortUrl\DropDefaultDomainFromRequestMiddleware;
|
||||
|
||||
class DropDefaultDomainFromRequestMiddlewareTest extends TestCase
|
||||
@@ -23,7 +24,9 @@ class DropDefaultDomainFromRequestMiddlewareTest extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->next = $this->createMock(RequestHandlerInterface::class);
|
||||
$this->middleware = new DropDefaultDomainFromRequestMiddleware('s.test');
|
||||
$this->middleware = new DropDefaultDomainFromRequestMiddleware(
|
||||
new UrlShortenerOptions(domain: ['hostname' => 's.test']),
|
||||
);
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideQueryParams')]
|
||||
|
||||
Reference in New Issue
Block a user