Updated to shlink-common with support for proxies for entities with public readonly props

This commit is contained in:
Alejandro Celaya 2023-01-16 23:41:14 +01:00
parent d8add9291f
commit c1b7c6ba6c
15 changed files with 21 additions and 26 deletions

View File

@ -46,7 +46,7 @@
"php-middleware/request-id": "^4.1",
"pugx/shortid-php": "^1.1",
"ramsey/uuid": "^4.5",
"shlinkio/shlink-common": "^5.2",
"shlinkio/shlink-common": "dev-main#61d26e7 as 5.3",
"shlinkio/shlink-config": "dev-main#2a5b5c2 as 2.4",
"shlinkio/shlink-event-dispatcher": "^2.6",
"shlinkio/shlink-importer": "^5.0",

View File

@ -51,7 +51,7 @@ class DomainService implements DomainServiceInterface
$repo = $this->em->getRepository(Domain::class);
$groups = group(
$repo->findDomains($apiKey),
fn (Domain $domain) => $domain->authority() === $this->defaultDomain ? 'default' : 'domains',
fn (Domain $domain) => $domain->authority === $this->defaultDomain ? 'default' : 'domains',
);
return [first($groups['default'] ?? []), $groups['domains'] ?? []];

View File

@ -15,7 +15,7 @@ class Domain extends AbstractEntity implements JsonSerializable, NotFoundRedirec
private ?string $regular404Redirect = null;
private ?string $invalidShortUrlRedirect = null;
private function __construct(private string $authority)
private function __construct(public readonly string $authority)
{
}
@ -24,11 +24,6 @@ class Domain extends AbstractEntity implements JsonSerializable, NotFoundRedirec
return new self($authority);
}
public function authority(): string
{
return $this->authority;
}
public function jsonSerialize(): string
{
return $this->authority;

View File

@ -20,7 +20,7 @@ final class DomainItem implements JsonSerializable
public static function forNonDefaultDomain(Domain $domain): self
{
return new self($domain->authority(), $domain, false);
return new self($domain->authority, $domain, false);
}
public static function forDefaultDomain(string $defaultDomain, NotFoundRedirectConfigInterface $config): self

View File

@ -28,6 +28,6 @@ class ShortUrlStringifier implements ShortUrlStringifierInterface
private function resolveDomain(ShortUrl $shortUrl): string
{
return $shortUrl->getDomain()?->authority() ?? $this->domainConfig['hostname'] ?? '';
return $shortUrl->getDomain()?->authority ?? $this->domainConfig['hostname'] ?? '';
}
}

View File

@ -45,7 +45,7 @@ final class ShortUrlIdentifier
public static function fromShortUrl(ShortUrl $shortUrl): self
{
$domain = $shortUrl->getDomain();
$domainAuthority = $domain?->authority();
$domainAuthority = $domain?->authority;
return new self($shortUrl->getShortCode(), $domainAuthority);
}

View File

@ -76,7 +76,7 @@ class UrlShortener implements UrlShortenerInterface
if (! $couldBeMadeUnique) {
$domain = $shortUrlToBeCreated->getDomain();
$domainAuthority = $domain?->authority();
$domainAuthority = $domain?->authority;
throw NonUniqueSlugException::fromSlug($shortUrlToBeCreated->getShortCode(), $domainAuthority);
}

View File

@ -131,7 +131,7 @@ class DomainRepositoryTest extends DatabaseTestCase
{
return ShortUrl::create(
ShortUrlCreation::fromRawData(
['domain' => $domain->authority(), 'apiKey' => $apiKey, 'longUrl' => 'foo'],
['domain' => $domain->authority, 'apiKey' => $apiKey, 'longUrl' => 'foo'],
),
new class ($domain) implements ShortUrlRelationResolverInterface {
public function __construct(private Domain $domain)

View File

@ -270,7 +270,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([
'validSince' => $start,
'apiKey' => $apiKey,
'domain' => $rightDomain->authority(),
'domain' => $rightDomain->authority,
'longUrl' => 'foo',
'tags' => ['foo', 'bar'],
]), $this->relationResolver);
@ -313,7 +313,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$shortUrl,
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
'validSince' => $start,
'domain' => $rightDomain->authority(),
'domain' => $rightDomain->authority,
'longUrl' => 'foo',
'tags' => ['foo', 'bar'],
])),
@ -322,7 +322,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$shortUrl,
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
'validSince' => $start,
'domain' => $rightDomain->authority(),
'domain' => $rightDomain->authority,
'apiKey' => $rightDomainApiKey,
'longUrl' => 'foo',
'tags' => ['foo', 'bar'],
@ -332,7 +332,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
$shortUrl,
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
'validSince' => $start,
'domain' => $rightDomain->authority(),
'domain' => $rightDomain->authority,
'apiKey' => $apiKey,
'longUrl' => 'foo',
'tags' => ['foo', 'bar'],
@ -341,7 +341,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
self::assertNull(
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
'validSince' => $start,
'domain' => $rightDomain->authority(),
'domain' => $rightDomain->authority,
'apiKey' => $wrongDomainApiKey,
'longUrl' => 'foo',
'tags' => ['foo', 'bar'],

View File

@ -249,7 +249,7 @@ class TagRepositoryTest extends DatabaseTestCase
$shortUrl2 = ShortUrl::create(
ShortUrlCreation::fromRawData(
['domain' => $domain->authority(), 'longUrl' => 'longUrl', 'tags' => $secondUrlTags],
['domain' => $domain->authority, 'longUrl' => 'longUrl', 'tags' => $secondUrlTags],
),
$this->relationResolver,
);

View File

@ -265,7 +265,7 @@ class VisitRepositoryTest extends DatabaseTestCase
$this->getEntityManager()->persist($apiKey1);
$shortUrl = ShortUrl::create(
ShortUrlCreation::fromRawData(
['apiKey' => $apiKey1, 'domain' => $domain->authority(), 'longUrl' => 'longUrl'],
['apiKey' => $apiKey1, 'domain' => $domain->authority, 'longUrl' => 'longUrl'],
),
$this->relationResolver,
);
@ -280,7 +280,7 @@ class VisitRepositoryTest extends DatabaseTestCase
$shortUrl3 = ShortUrl::create(
ShortUrlCreation::fromRawData(
['apiKey' => $apiKey2, 'domain' => $domain->authority(), 'longUrl' => 'longUrl'],
['apiKey' => $apiKey2, 'domain' => $domain->authority, 'longUrl' => 'longUrl'],
),
$this->relationResolver,
);

View File

@ -52,7 +52,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
self::assertSame($result, $foundDomain);
}
self::assertInstanceOf(Domain::class, $result);
self::assertEquals($authority, $result->authority());
self::assertEquals($authority, $result->authority);
}
public function provideFoundDomains(): iterable

View File

@ -30,7 +30,7 @@ class SimpleShortUrlRelationResolverTest extends TestCase
self::assertNull($result);
} else {
self::assertInstanceOf(Domain::class, $result);
self::assertEquals($domain, $result->authority());
self::assertEquals($domain, $result->authority);
}
}

View File

@ -22,7 +22,7 @@ final class RoleDefinition
{
return new self(
Role::DOMAIN_SPECIFIC,
['domain_id' => $domain->getId(), 'authority' => $domain->authority()],
['domain_id' => $domain->getId(), 'authority' => $domain->authority],
);
}
}

View File

@ -34,11 +34,11 @@ class OverrideDomainMiddleware implements MiddlewareInterface
if ($requestMethod === RequestMethodInterface::METHOD_POST) {
/** @var array $payload */
$payload = $request->getParsedBody();
$payload[ShortUrlInputFilter::DOMAIN] = $domain->authority();
$payload[ShortUrlInputFilter::DOMAIN] = $domain->authority;
return $handler->handle($request->withParsedBody($payload));
}
return $handler->handle($request->withAttribute(ShortUrlInputFilter::DOMAIN, $domain->authority()));
return $handler->handle($request->withAttribute(ShortUrlInputFilter::DOMAIN, $domain->authority));
}
}