Inject ShortUrlRepository in UrlShortener

This commit is contained in:
Alejandro Celaya
2024-11-09 09:43:55 +01:00
parent 532102e662
commit 3ec24e3c67
3 changed files with 14 additions and 13 deletions

View File

@@ -17,14 +17,15 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\UrlShorteningResult;
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
use Shlinkio\Shlink\Core\ShortUrl\Resolver\ShortUrlRelationResolverInterface;
class UrlShortener implements UrlShortenerInterface
readonly class UrlShortener implements UrlShortenerInterface
{
public function __construct(
private readonly ShortUrlTitleResolutionHelperInterface $titleResolutionHelper,
private readonly EntityManagerInterface $em,
private readonly ShortUrlRelationResolverInterface $relationResolver,
private readonly ShortCodeUniquenessHelperInterface $shortCodeHelper,
private readonly EventDispatcherInterface $eventDispatcher,
private ShortUrlTitleResolutionHelperInterface $titleResolutionHelper,
private EntityManagerInterface $em,
private ShortUrlRelationResolverInterface $relationResolver,
private ShortCodeUniquenessHelperInterface $shortCodeHelper,
private EventDispatcherInterface $eventDispatcher,
private ShortUrlRepositoryInterface $repo,
) {
}
@@ -70,9 +71,7 @@ class UrlShortener implements UrlShortenerInterface
return null;
}
/** @var ShortUrlRepositoryInterface $repo */
$repo = $this->em->getRepository(ShortUrl::class);
return $repo->findOneMatching($creation);
return $this->repo->findOneMatching($creation);
}
private function verifyShortCodeUniqueness(ShortUrlCreation $meta, ShortUrl $shortUrlToBeCreated): void