Allow to determine if remote addresses should be obfuscated at configuration level

This commit is contained in:
Alejandro Celaya 2020-05-08 13:10:58 +02:00
parent 7da00fbc8c
commit eac468514b
4 changed files with 15 additions and 5 deletions

View file

@ -12,6 +12,7 @@ return [
'hostname' => '',
],
'validate_url' => false,
'obfuscate_remote_addr' => true,
'visits_webhooks' => [],
'default_short_codes_length' => DEFAULT_SHORT_CODES_LENGTH,
],

View file

@ -54,7 +54,11 @@ return [
Options\UrlShortenerOptions::class => ['config.url_shortener'],
Service\UrlShortener::class => [Util\UrlValidator::class, 'em', Resolver\PersistenceDomainResolver::class],
Service\VisitsTracker::class => ['em', EventDispatcherInterface::class],
Service\VisitsTracker::class => [
'em',
EventDispatcherInterface::class,
'config.url_shortener.obfuscate_remote_addr',
],
Service\ShortUrlService::class => ['em', Service\ShortUrl\ShortUrlResolver::class, Util\UrlValidator::class],
Visit\VisitLocator::class => ['em'],
Visit\VisitsStatsHelper::class => ['em'],

View file

@ -22,11 +22,16 @@ class VisitsTracker implements VisitsTrackerInterface
{
private ORM\EntityManagerInterface $em;
private EventDispatcherInterface $eventDispatcher;
private bool $obfuscateRemoteAddr;
public function __construct(ORM\EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher)
{
public function __construct(
ORM\EntityManagerInterface $em,
EventDispatcherInterface $eventDispatcher,
bool $obfuscateRemoteAddr
) {
$this->em = $em;
$this->eventDispatcher = $eventDispatcher;
$this->obfuscateRemoteAddr = $obfuscateRemoteAddr;
}
/**
@ -34,7 +39,7 @@ class VisitsTracker implements VisitsTrackerInterface
*/
public function track(ShortUrl $shortUrl, Visitor $visitor): void
{
$visit = new Visit($shortUrl, $visitor);
$visit = new Visit($shortUrl, $visitor, $this->obfuscateRemoteAddr);
$this->em->persist($visit);
$this->em->flush();

View file

@ -37,7 +37,7 @@ class VisitsTrackerTest extends TestCase
$this->em = $this->prophesize(EntityManager::class);
$this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
$this->visitsTracker = new VisitsTracker($this->em->reveal(), $this->eventDispatcher->reveal());
$this->visitsTracker = new VisitsTracker($this->em->reveal(), $this->eventDispatcher->reveal(), true);
}
/** @test */