mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-22 14:33:16 -06:00
Migrated NotFoundRedirectOptions to immutable object
This commit is contained in:
parent
39693ca1fe
commit
20f457a3e9
@ -43,10 +43,10 @@ class ListDomainsCommandTest extends TestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
$listDomains = $this->domainService->listDomains()->willReturn([
|
$listDomains = $this->domainService->listDomains()->willReturn([
|
||||||
DomainItem::forDefaultDomain('foo.com', new NotFoundRedirectOptions([
|
DomainItem::forDefaultDomain('foo.com', new NotFoundRedirectOptions(
|
||||||
'base_url' => 'https://foo.com/default/base',
|
invalidShortUrl: 'https://foo.com/default/invalid',
|
||||||
'invalid_short_url' => 'https://foo.com/default/invalid',
|
baseUrl: 'https://foo.com/default/base',
|
||||||
])),
|
)),
|
||||||
DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com')),
|
DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com')),
|
||||||
DomainItem::forNonDefaultDomain($bazDomain),
|
DomainItem::forNonDefaultDomain($bazDomain),
|
||||||
]);
|
]);
|
||||||
|
@ -23,7 +23,7 @@ return [
|
|||||||
|
|
||||||
Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'],
|
Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'],
|
||||||
Options\DeleteShortUrlsOptions::class => [ValinorConfigFactory::class, 'config.delete_short_urls'],
|
Options\DeleteShortUrlsOptions::class => [ValinorConfigFactory::class, 'config.delete_short_urls'],
|
||||||
Options\NotFoundRedirectOptions::class => ConfigAbstractFactory::class,
|
Options\NotFoundRedirectOptions::class => [ValinorConfigFactory::class, 'config.not_found_redirects'],
|
||||||
Options\RedirectOptions::class => ConfigAbstractFactory::class,
|
Options\RedirectOptions::class => ConfigAbstractFactory::class,
|
||||||
Options\UrlShortenerOptions::class => ConfigAbstractFactory::class,
|
Options\UrlShortenerOptions::class => ConfigAbstractFactory::class,
|
||||||
Options\TrackingOptions::class => [ValinorConfigFactory::class, 'config.tracking'],
|
Options\TrackingOptions::class => [ValinorConfigFactory::class, 'config.tracking'],
|
||||||
@ -86,7 +86,6 @@ return [
|
|||||||
Domain\DomainService::class,
|
Domain\DomainService::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
Options\NotFoundRedirectOptions::class => ['config.not_found_redirects'],
|
|
||||||
Options\RedirectOptions::class => ['config.redirects'],
|
Options\RedirectOptions::class => ['config.redirects'],
|
||||||
Options\UrlShortenerOptions::class => ['config.url_shortener'],
|
Options\UrlShortenerOptions::class => ['config.url_shortener'],
|
||||||
Options\QrCodeOptions::class => ['config.qr_codes'],
|
Options\QrCodeOptions::class => ['config.qr_codes'],
|
||||||
|
@ -4,14 +4,16 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\Core\Options;
|
namespace Shlinkio\Shlink\Core\Options;
|
||||||
|
|
||||||
use Laminas\Stdlib\AbstractOptions;
|
|
||||||
use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface;
|
use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface;
|
||||||
|
|
||||||
class NotFoundRedirectOptions extends AbstractOptions implements NotFoundRedirectConfigInterface
|
final class NotFoundRedirectOptions implements NotFoundRedirectConfigInterface
|
||||||
{
|
{
|
||||||
private ?string $invalidShortUrl = null;
|
public function __construct(
|
||||||
private ?string $regular404 = null;
|
public readonly ?string $invalidShortUrl = null,
|
||||||
private ?string $baseUrl = null;
|
public readonly ?string $regular404 = null,
|
||||||
|
public readonly ?string $baseUrl = null,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public function invalidShortUrlRedirect(): ?string
|
public function invalidShortUrlRedirect(): ?string
|
||||||
{
|
{
|
||||||
@ -23,12 +25,6 @@ class NotFoundRedirectOptions extends AbstractOptions implements NotFoundRedirec
|
|||||||
return $this->invalidShortUrl !== null;
|
return $this->invalidShortUrl !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setInvalidShortUrl(?string $invalidShortUrl): self
|
|
||||||
{
|
|
||||||
$this->invalidShortUrl = $invalidShortUrl;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function regular404Redirect(): ?string
|
public function regular404Redirect(): ?string
|
||||||
{
|
{
|
||||||
return $this->regular404;
|
return $this->regular404;
|
||||||
@ -39,12 +35,6 @@ class NotFoundRedirectOptions extends AbstractOptions implements NotFoundRedirec
|
|||||||
return $this->regular404 !== null;
|
return $this->regular404 !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setRegular404(?string $regular404): self
|
|
||||||
{
|
|
||||||
$this->regular404 = $regular404;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function baseUrlRedirect(): ?string
|
public function baseUrlRedirect(): ?string
|
||||||
{
|
{
|
||||||
return $this->baseUrl;
|
return $this->baseUrl;
|
||||||
@ -54,10 +44,4 @@ class NotFoundRedirectOptions extends AbstractOptions implements NotFoundRedirec
|
|||||||
{
|
{
|
||||||
return $this->baseUrl !== null;
|
return $this->baseUrl !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setBaseUrl(?string $baseUrl): self
|
|
||||||
{
|
|
||||||
$this->baseUrl = $baseUrl;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -60,57 +60,57 @@ class NotFoundRedirectResolverTest extends TestCase
|
|||||||
yield 'base URL with trailing slash' => [
|
yield 'base URL with trailing slash' => [
|
||||||
$uri = new Uri('/'),
|
$uri = new Uri('/'),
|
||||||
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
||||||
new NotFoundRedirectOptions(['baseUrl' => 'baseUrl']),
|
new NotFoundRedirectOptions(baseUrl: 'baseUrl'),
|
||||||
'baseUrl',
|
'baseUrl',
|
||||||
];
|
];
|
||||||
yield 'base URL with domain placeholder' => [
|
yield 'base URL with domain placeholder' => [
|
||||||
$uri = new Uri('https://doma.in'),
|
$uri = new Uri('https://doma.in'),
|
||||||
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
||||||
new NotFoundRedirectOptions(['baseUrl' => 'https://redirect-here.com/{DOMAIN}']),
|
new NotFoundRedirectOptions(baseUrl: 'https://redirect-here.com/{DOMAIN}'),
|
||||||
'https://redirect-here.com/doma.in',
|
'https://redirect-here.com/doma.in',
|
||||||
];
|
];
|
||||||
yield 'base URL with domain placeholder in query' => [
|
yield 'base URL with domain placeholder in query' => [
|
||||||
$uri = new Uri('https://doma.in'),
|
$uri = new Uri('https://doma.in'),
|
||||||
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
||||||
new NotFoundRedirectOptions(['baseUrl' => 'https://redirect-here.com/?domain={DOMAIN}']),
|
new NotFoundRedirectOptions(baseUrl: 'https://redirect-here.com/?domain={DOMAIN}'),
|
||||||
'https://redirect-here.com/?domain=doma.in',
|
'https://redirect-here.com/?domain=doma.in',
|
||||||
];
|
];
|
||||||
yield 'base URL without trailing slash' => [
|
yield 'base URL without trailing slash' => [
|
||||||
$uri = new Uri(''),
|
$uri = new Uri(''),
|
||||||
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
||||||
new NotFoundRedirectOptions(['baseUrl' => 'baseUrl']),
|
new NotFoundRedirectOptions(baseUrl: 'baseUrl'),
|
||||||
'baseUrl',
|
'baseUrl',
|
||||||
];
|
];
|
||||||
yield 'regular 404' => [
|
yield 'regular 404' => [
|
||||||
$uri = new Uri('/foo/bar'),
|
$uri = new Uri('/foo/bar'),
|
||||||
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
||||||
new NotFoundRedirectOptions(['regular404' => 'regular404']),
|
new NotFoundRedirectOptions(regular404: 'regular404'),
|
||||||
'regular404',
|
'regular404',
|
||||||
];
|
];
|
||||||
yield 'regular 404 with path placeholder in query' => [
|
yield 'regular 404 with path placeholder in query' => [
|
||||||
$uri = new Uri('/foo/bar'),
|
$uri = new Uri('/foo/bar'),
|
||||||
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
||||||
new NotFoundRedirectOptions(['regular404' => 'https://redirect-here.com/?path={ORIGINAL_PATH}']),
|
new NotFoundRedirectOptions(regular404: 'https://redirect-here.com/?path={ORIGINAL_PATH}'),
|
||||||
'https://redirect-here.com/?path=%2Ffoo%2Fbar',
|
'https://redirect-here.com/?path=%2Ffoo%2Fbar',
|
||||||
];
|
];
|
||||||
yield 'regular 404 with multiple placeholders' => [
|
yield 'regular 404 with multiple placeholders' => [
|
||||||
$uri = new Uri('https://doma.in/foo/bar'),
|
$uri = new Uri('https://doma.in/foo/bar'),
|
||||||
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
$this->notFoundType(ServerRequestFactory::fromGlobals()->withUri($uri)),
|
||||||
new NotFoundRedirectOptions([
|
new NotFoundRedirectOptions(
|
||||||
'regular404' => 'https://redirect-here.com/{ORIGINAL_PATH}/{DOMAIN}/?d={DOMAIN}&p={ORIGINAL_PATH}',
|
regular404: 'https://redirect-here.com/{ORIGINAL_PATH}/{DOMAIN}/?d={DOMAIN}&p={ORIGINAL_PATH}',
|
||||||
]),
|
),
|
||||||
'https://redirect-here.com/foo/bar/doma.in/?d=doma.in&p=%2Ffoo%2Fbar',
|
'https://redirect-here.com/foo/bar/doma.in/?d=doma.in&p=%2Ffoo%2Fbar',
|
||||||
];
|
];
|
||||||
yield 'invalid short URL' => [
|
yield 'invalid short URL' => [
|
||||||
new Uri('/foo'),
|
new Uri('/foo'),
|
||||||
$this->notFoundType($this->requestForRoute(RedirectAction::class)),
|
$this->notFoundType($this->requestForRoute(RedirectAction::class)),
|
||||||
new NotFoundRedirectOptions(['invalidShortUrl' => 'invalidShortUrl']),
|
new NotFoundRedirectOptions(invalidShortUrl: 'invalidShortUrl'),
|
||||||
'invalidShortUrl',
|
'invalidShortUrl',
|
||||||
];
|
];
|
||||||
yield 'invalid short URL with path placeholder' => [
|
yield 'invalid short URL with path placeholder' => [
|
||||||
new Uri('/foo'),
|
new Uri('/foo'),
|
||||||
$this->notFoundType($this->requestForRoute(RedirectAction::class)),
|
$this->notFoundType($this->requestForRoute(RedirectAction::class)),
|
||||||
new NotFoundRedirectOptions(['invalidShortUrl' => 'https://redirect-here.com/{ORIGINAL_PATH}']),
|
new NotFoundRedirectOptions(invalidShortUrl: 'https://redirect-here.com/{ORIGINAL_PATH}'),
|
||||||
'https://redirect-here.com/foo',
|
'https://redirect-here.com/foo',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class DomainRedirectsRequestTest extends TestCase
|
|||||||
yield 'some values' => [['domain' => 'foo', 'regular404Redirect' => 'bar'], null, 'foo', null, 'bar', null];
|
yield 'some values' => [['domain' => 'foo', 'regular404Redirect' => 'bar'], null, 'foo', null, 'bar', null];
|
||||||
yield 'fallbacks' => [
|
yield 'fallbacks' => [
|
||||||
['domain' => 'domain', 'baseUrlRedirect' => 'bar'],
|
['domain' => 'domain', 'baseUrlRedirect' => 'bar'],
|
||||||
new NotFoundRedirectOptions(['regular404' => 'fallback', 'invalidShortUrl' => 'fallback2']),
|
new NotFoundRedirectOptions(invalidShortUrl: 'fallback2', regular404: 'fallback'),
|
||||||
'domain',
|
'domain',
|
||||||
'bar',
|
'bar',
|
||||||
'fallback',
|
'fallback',
|
||||||
@ -63,7 +63,7 @@ class DomainRedirectsRequestTest extends TestCase
|
|||||||
];
|
];
|
||||||
yield 'fallback ignored' => [
|
yield 'fallback ignored' => [
|
||||||
['domain' => 'domain', 'regular404Redirect' => 'bar', 'invalidShortUrlRedirect' => null],
|
['domain' => 'domain', 'regular404Redirect' => 'bar', 'invalidShortUrlRedirect' => null],
|
||||||
new NotFoundRedirectOptions(['regular404' => 'fallback', 'invalidShortUrl' => 'fallback2']),
|
new NotFoundRedirectOptions(invalidShortUrl: 'fallback2', regular404: 'fallback'),
|
||||||
'domain',
|
'domain',
|
||||||
null,
|
null,
|
||||||
'bar',
|
'bar',
|
||||||
|
Loading…
Reference in New Issue
Block a user