mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-25 18:30:23 -06:00
Updated VisitsTracker so that the track method expects a Request object to be provided
This commit is contained in:
parent
34753ca7d3
commit
73a236b3d0
@ -85,7 +85,7 @@ class RedirectAction implements MiddlewareInterface
|
||||
}
|
||||
|
||||
// Track visit to this short code
|
||||
$this->visitTracker->track($shortCode);
|
||||
$this->visitTracker->track($shortCode, $request);
|
||||
|
||||
// Return a redirect response to the long URL.
|
||||
// Use a temporary redirect to make sure browsers always hit the server for analytics purposes
|
||||
|
@ -3,6 +3,7 @@ namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation\Inject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
@ -31,11 +32,11 @@ class VisitsTracker implements VisitsTrackerInterface
|
||||
* Tracks a new visit to provided short code, using an array of data to look up information
|
||||
*
|
||||
* @param string $shortCode
|
||||
* @param array $visitorData Defaults to global $_SERVER
|
||||
* @param ServerRequestInterface $request
|
||||
*/
|
||||
public function track($shortCode, array $visitorData = null)
|
||||
public function track($shortCode, ServerRequestInterface $request)
|
||||
{
|
||||
$visitorData = $visitorData ?: $_SERVER;
|
||||
$visitorData = $request->getServerParams();
|
||||
|
||||
/** @var ShortUrl $shortUrl */
|
||||
$shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy([
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Shlinkio\Shlink\Core\Service;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
|
||||
@ -10,9 +11,10 @@ interface VisitsTrackerInterface
|
||||
* Tracks a new visit to provided short code, using an array of data to look up information
|
||||
*
|
||||
* @param string $shortCode
|
||||
* @param array $visitorData Defaults to global $_SERVER
|
||||
* @param ServerRequestInterface $request
|
||||
* @return
|
||||
*/
|
||||
public function track($shortCode, array $visitorData = null);
|
||||
public function track($shortCode, ServerRequestInterface $request);
|
||||
|
||||
/**
|
||||
* Returns the visits on certain short code
|
||||
|
@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Repository\VisitRepository;
|
||||
use Shlinkio\Shlink\Core\Service\VisitsTracker;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
|
||||
class VisitsTrackerTest extends TestCase
|
||||
{
|
||||
@ -41,7 +42,7 @@ class VisitsTrackerTest extends TestCase
|
||||
$this->em->persist(Argument::any())->shouldBeCalledTimes(1);
|
||||
$this->em->flush()->shouldBeCalledTimes(1);
|
||||
|
||||
$this->visitsTracker->track($shortCode);
|
||||
$this->visitsTracker->track($shortCode, ServerRequestFactory::fromGlobals());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user