mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Fixed merge conflicts
This commit is contained in:
@@ -42,7 +42,13 @@ return [
|
||||
NotFoundDelegate::class => [TemplateRendererInterface::class],
|
||||
|
||||
// Services
|
||||
Service\UrlShortener::class => ['httpClient', 'em', Cache::class, 'config.url_shortener.shortcode_chars'],
|
||||
Service\UrlShortener::class => [
|
||||
'httpClient',
|
||||
'em',
|
||||
Cache::class,
|
||||
'config.url_shortener.validate_url',
|
||||
'config.url_shortener.shortcode_chars',
|
||||
],
|
||||
Service\VisitsTracker::class => ['em'],
|
||||
Service\ShortUrlService::class => ['em'],
|
||||
Service\VisitService::class => ['em'],
|
||||
|
||||
@@ -46,18 +46,24 @@ class UrlShortener implements UrlShortenerInterface
|
||||
* @var SlugifyInterface
|
||||
*/
|
||||
private $slugger;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $urlValidationEnabled;
|
||||
|
||||
public function __construct(
|
||||
ClientInterface $httpClient,
|
||||
EntityManagerInterface $em,
|
||||
Cache $cache,
|
||||
$urlValidationEnabled,
|
||||
$chars = self::DEFAULT_CHARS,
|
||||
SlugifyInterface $slugger = null
|
||||
) {
|
||||
$this->httpClient = $httpClient;
|
||||
$this->em = $em;
|
||||
$this->chars = empty($chars) ? self::DEFAULT_CHARS : $chars;
|
||||
$this->cache = $cache;
|
||||
$this->urlValidationEnabled = $urlValidationEnabled;
|
||||
$this->chars = empty($chars) ? self::DEFAULT_CHARS : $chars;
|
||||
$this->slugger = $slugger ?: new Slugify();
|
||||
}
|
||||
|
||||
@@ -91,8 +97,11 @@ class UrlShortener implements UrlShortenerInterface
|
||||
return $shortUrl->getShortCode();
|
||||
}
|
||||
|
||||
// Check that the URL exists
|
||||
$this->checkUrlExists($url);
|
||||
// Check if the validation of url is enabled in the config
|
||||
if (true === $this->urlValidationEnabled) {
|
||||
// Check that the URL exists
|
||||
$this->checkUrlExists($url);
|
||||
}
|
||||
$customSlug = $this->processCustomSlug($customSlug);
|
||||
|
||||
// Transactionally insert the short url, then generate the short code and finally update the short code
|
||||
|
||||
@@ -69,10 +69,19 @@ class UrlShortenerTest extends TestCase
|
||||
$this->cache = new ArrayCache();
|
||||
$this->slugger = $this->prophesize(SlugifyInterface::class);
|
||||
|
||||
$this->setUrlShortener(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $urlValidationEnabled
|
||||
*/
|
||||
public function setUrlShortener($urlValidationEnabled)
|
||||
{
|
||||
$this->urlShortener = new UrlShortener(
|
||||
$this->httpClient->reveal(),
|
||||
$this->em->reveal(),
|
||||
$this->cache,
|
||||
$urlValidationEnabled,
|
||||
UrlShortener::DEFAULT_CHARS,
|
||||
$this->slugger->reveal()
|
||||
);
|
||||
@@ -110,6 +119,8 @@ class UrlShortenerTest extends TestCase
|
||||
*/
|
||||
public function exceptionIsThrownWhenUrlDoesNotExist()
|
||||
{
|
||||
$this->setUrlShortener(true);
|
||||
|
||||
$this->httpClient->request(Argument::cetera())->willThrow(
|
||||
new ClientException('', $this->prophesize(Request::class)->reveal())
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user