mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Updated to shlink-common with support for proxies for entities with public readonly props
This commit is contained in:
@@ -46,7 +46,7 @@
|
|||||||
"php-middleware/request-id": "^4.1",
|
"php-middleware/request-id": "^4.1",
|
||||||
"pugx/shortid-php": "^1.1",
|
"pugx/shortid-php": "^1.1",
|
||||||
"ramsey/uuid": "^4.5",
|
"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-config": "dev-main#2a5b5c2 as 2.4",
|
||||||
"shlinkio/shlink-event-dispatcher": "^2.6",
|
"shlinkio/shlink-event-dispatcher": "^2.6",
|
||||||
"shlinkio/shlink-importer": "^5.0",
|
"shlinkio/shlink-importer": "^5.0",
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class DomainService implements DomainServiceInterface
|
|||||||
$repo = $this->em->getRepository(Domain::class);
|
$repo = $this->em->getRepository(Domain::class);
|
||||||
$groups = group(
|
$groups = group(
|
||||||
$repo->findDomains($apiKey),
|
$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'] ?? []];
|
return [first($groups['default'] ?? []), $groups['domains'] ?? []];
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class Domain extends AbstractEntity implements JsonSerializable, NotFoundRedirec
|
|||||||
private ?string $regular404Redirect = null;
|
private ?string $regular404Redirect = null;
|
||||||
private ?string $invalidShortUrlRedirect = 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);
|
return new self($authority);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authority(): string
|
|
||||||
{
|
|
||||||
return $this->authority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonSerialize(): string
|
public function jsonSerialize(): string
|
||||||
{
|
{
|
||||||
return $this->authority;
|
return $this->authority;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ final class DomainItem implements JsonSerializable
|
|||||||
|
|
||||||
public static function forNonDefaultDomain(Domain $domain): self
|
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
|
public static function forDefaultDomain(string $defaultDomain, NotFoundRedirectConfigInterface $config): self
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ class ShortUrlStringifier implements ShortUrlStringifierInterface
|
|||||||
|
|
||||||
private function resolveDomain(ShortUrl $shortUrl): string
|
private function resolveDomain(ShortUrl $shortUrl): string
|
||||||
{
|
{
|
||||||
return $shortUrl->getDomain()?->authority() ?? $this->domainConfig['hostname'] ?? '';
|
return $shortUrl->getDomain()?->authority ?? $this->domainConfig['hostname'] ?? '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ final class ShortUrlIdentifier
|
|||||||
public static function fromShortUrl(ShortUrl $shortUrl): self
|
public static function fromShortUrl(ShortUrl $shortUrl): self
|
||||||
{
|
{
|
||||||
$domain = $shortUrl->getDomain();
|
$domain = $shortUrl->getDomain();
|
||||||
$domainAuthority = $domain?->authority();
|
$domainAuthority = $domain?->authority;
|
||||||
|
|
||||||
return new self($shortUrl->getShortCode(), $domainAuthority);
|
return new self($shortUrl->getShortCode(), $domainAuthority);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class UrlShortener implements UrlShortenerInterface
|
|||||||
|
|
||||||
if (! $couldBeMadeUnique) {
|
if (! $couldBeMadeUnique) {
|
||||||
$domain = $shortUrlToBeCreated->getDomain();
|
$domain = $shortUrlToBeCreated->getDomain();
|
||||||
$domainAuthority = $domain?->authority();
|
$domainAuthority = $domain?->authority;
|
||||||
|
|
||||||
throw NonUniqueSlugException::fromSlug($shortUrlToBeCreated->getShortCode(), $domainAuthority);
|
throw NonUniqueSlugException::fromSlug($shortUrlToBeCreated->getShortCode(), $domainAuthority);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class DomainRepositoryTest extends DatabaseTestCase
|
|||||||
{
|
{
|
||||||
return ShortUrl::create(
|
return ShortUrl::create(
|
||||||
ShortUrlCreation::fromRawData(
|
ShortUrlCreation::fromRawData(
|
||||||
['domain' => $domain->authority(), 'apiKey' => $apiKey, 'longUrl' => 'foo'],
|
['domain' => $domain->authority, 'apiKey' => $apiKey, 'longUrl' => 'foo'],
|
||||||
),
|
),
|
||||||
new class ($domain) implements ShortUrlRelationResolverInterface {
|
new class ($domain) implements ShortUrlRelationResolverInterface {
|
||||||
public function __construct(private Domain $domain)
|
public function __construct(private Domain $domain)
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([
|
$shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([
|
||||||
'validSince' => $start,
|
'validSince' => $start,
|
||||||
'apiKey' => $apiKey,
|
'apiKey' => $apiKey,
|
||||||
'domain' => $rightDomain->authority(),
|
'domain' => $rightDomain->authority,
|
||||||
'longUrl' => 'foo',
|
'longUrl' => 'foo',
|
||||||
'tags' => ['foo', 'bar'],
|
'tags' => ['foo', 'bar'],
|
||||||
]), $this->relationResolver);
|
]), $this->relationResolver);
|
||||||
@@ -313,7 +313,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
$shortUrl,
|
$shortUrl,
|
||||||
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
||||||
'validSince' => $start,
|
'validSince' => $start,
|
||||||
'domain' => $rightDomain->authority(),
|
'domain' => $rightDomain->authority,
|
||||||
'longUrl' => 'foo',
|
'longUrl' => 'foo',
|
||||||
'tags' => ['foo', 'bar'],
|
'tags' => ['foo', 'bar'],
|
||||||
])),
|
])),
|
||||||
@@ -322,7 +322,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
$shortUrl,
|
$shortUrl,
|
||||||
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
||||||
'validSince' => $start,
|
'validSince' => $start,
|
||||||
'domain' => $rightDomain->authority(),
|
'domain' => $rightDomain->authority,
|
||||||
'apiKey' => $rightDomainApiKey,
|
'apiKey' => $rightDomainApiKey,
|
||||||
'longUrl' => 'foo',
|
'longUrl' => 'foo',
|
||||||
'tags' => ['foo', 'bar'],
|
'tags' => ['foo', 'bar'],
|
||||||
@@ -332,7 +332,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
$shortUrl,
|
$shortUrl,
|
||||||
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
||||||
'validSince' => $start,
|
'validSince' => $start,
|
||||||
'domain' => $rightDomain->authority(),
|
'domain' => $rightDomain->authority,
|
||||||
'apiKey' => $apiKey,
|
'apiKey' => $apiKey,
|
||||||
'longUrl' => 'foo',
|
'longUrl' => 'foo',
|
||||||
'tags' => ['foo', 'bar'],
|
'tags' => ['foo', 'bar'],
|
||||||
@@ -341,7 +341,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
self::assertNull(
|
self::assertNull(
|
||||||
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
$this->repo->findOneMatching(ShortUrlCreation::fromRawData([
|
||||||
'validSince' => $start,
|
'validSince' => $start,
|
||||||
'domain' => $rightDomain->authority(),
|
'domain' => $rightDomain->authority,
|
||||||
'apiKey' => $wrongDomainApiKey,
|
'apiKey' => $wrongDomainApiKey,
|
||||||
'longUrl' => 'foo',
|
'longUrl' => 'foo',
|
||||||
'tags' => ['foo', 'bar'],
|
'tags' => ['foo', 'bar'],
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ class TagRepositoryTest extends DatabaseTestCase
|
|||||||
|
|
||||||
$shortUrl2 = ShortUrl::create(
|
$shortUrl2 = ShortUrl::create(
|
||||||
ShortUrlCreation::fromRawData(
|
ShortUrlCreation::fromRawData(
|
||||||
['domain' => $domain->authority(), 'longUrl' => 'longUrl', 'tags' => $secondUrlTags],
|
['domain' => $domain->authority, 'longUrl' => 'longUrl', 'tags' => $secondUrlTags],
|
||||||
),
|
),
|
||||||
$this->relationResolver,
|
$this->relationResolver,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
|||||||
$this->getEntityManager()->persist($apiKey1);
|
$this->getEntityManager()->persist($apiKey1);
|
||||||
$shortUrl = ShortUrl::create(
|
$shortUrl = ShortUrl::create(
|
||||||
ShortUrlCreation::fromRawData(
|
ShortUrlCreation::fromRawData(
|
||||||
['apiKey' => $apiKey1, 'domain' => $domain->authority(), 'longUrl' => 'longUrl'],
|
['apiKey' => $apiKey1, 'domain' => $domain->authority, 'longUrl' => 'longUrl'],
|
||||||
),
|
),
|
||||||
$this->relationResolver,
|
$this->relationResolver,
|
||||||
);
|
);
|
||||||
@@ -280,7 +280,7 @@ class VisitRepositoryTest extends DatabaseTestCase
|
|||||||
|
|
||||||
$shortUrl3 = ShortUrl::create(
|
$shortUrl3 = ShortUrl::create(
|
||||||
ShortUrlCreation::fromRawData(
|
ShortUrlCreation::fromRawData(
|
||||||
['apiKey' => $apiKey2, 'domain' => $domain->authority(), 'longUrl' => 'longUrl'],
|
['apiKey' => $apiKey2, 'domain' => $domain->authority, 'longUrl' => 'longUrl'],
|
||||||
),
|
),
|
||||||
$this->relationResolver,
|
$this->relationResolver,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class PersistenceShortUrlRelationResolverTest extends TestCase
|
|||||||
self::assertSame($result, $foundDomain);
|
self::assertSame($result, $foundDomain);
|
||||||
}
|
}
|
||||||
self::assertInstanceOf(Domain::class, $result);
|
self::assertInstanceOf(Domain::class, $result);
|
||||||
self::assertEquals($authority, $result->authority());
|
self::assertEquals($authority, $result->authority);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideFoundDomains(): iterable
|
public function provideFoundDomains(): iterable
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class SimpleShortUrlRelationResolverTest extends TestCase
|
|||||||
self::assertNull($result);
|
self::assertNull($result);
|
||||||
} else {
|
} else {
|
||||||
self::assertInstanceOf(Domain::class, $result);
|
self::assertInstanceOf(Domain::class, $result);
|
||||||
self::assertEquals($domain, $result->authority());
|
self::assertEquals($domain, $result->authority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ final class RoleDefinition
|
|||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
Role::DOMAIN_SPECIFIC,
|
Role::DOMAIN_SPECIFIC,
|
||||||
['domain_id' => $domain->getId(), 'authority' => $domain->authority()],
|
['domain_id' => $domain->getId(), 'authority' => $domain->authority],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ class OverrideDomainMiddleware implements MiddlewareInterface
|
|||||||
if ($requestMethod === RequestMethodInterface::METHOD_POST) {
|
if ($requestMethod === RequestMethodInterface::METHOD_POST) {
|
||||||
/** @var array $payload */
|
/** @var array $payload */
|
||||||
$payload = $request->getParsedBody();
|
$payload = $request->getParsedBody();
|
||||||
$payload[ShortUrlInputFilter::DOMAIN] = $domain->authority();
|
$payload[ShortUrlInputFilter::DOMAIN] = $domain->authority;
|
||||||
|
|
||||||
return $handler->handle($request->withParsedBody($payload));
|
return $handler->handle($request->withParsedBody($payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $handler->handle($request->withAttribute(ShortUrlInputFilter::DOMAIN, $domain->authority()));
|
return $handler->handle($request->withAttribute(ShortUrlInputFilter::DOMAIN, $domain->authority));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user