Merge pull request #1061 from acelaya-forks/feature/update-mercure

Updated to symfony/mercure 0.5
This commit is contained in:
Alejandro Celaya 2021-04-02 09:59:31 +02:00 committed by GitHub
commit 731dc64f44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 21 deletions

View file

@ -46,7 +46,7 @@
"predis/predis": "^1.1", "predis/predis": "^1.1",
"pugx/shortid-php": "^0.7", "pugx/shortid-php": "^0.7",
"ramsey/uuid": "^3.9", "ramsey/uuid": "^3.9",
"shlinkio/shlink-common": "^3.6", "shlinkio/shlink-common": "dev-main#3777189 as 3.7",
"shlinkio/shlink-config": "^1.0", "shlinkio/shlink-config": "^1.0",
"shlinkio/shlink-event-dispatcher": "^2.1", "shlinkio/shlink-event-dispatcher": "^2.1",
"shlinkio/shlink-importer": "^2.2", "shlinkio/shlink-importer": "^2.2",
@ -55,7 +55,7 @@
"symfony/console": "^5.1", "symfony/console": "^5.1",
"symfony/filesystem": "^5.1", "symfony/filesystem": "^5.1",
"symfony/lock": "^5.1", "symfony/lock": "^5.1",
"symfony/mercure": "^0.4.1", "symfony/mercure": "^0.5.1",
"symfony/process": "^5.1", "symfony/process": "^5.1",
"symfony/string": "^5.1" "symfony/string": "^5.1"
}, },

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
use Laminas\ServiceManager\Proxy\LazyServiceFactory; use Laminas\ServiceManager\Proxy\LazyServiceFactory;
use Shlinkio\Shlink\Common\Mercure\LcobucciJwtProvider; use Shlinkio\Shlink\Common\Mercure\LcobucciJwtProvider;
use Symfony\Component\Mercure\Publisher; use Symfony\Component\Mercure\Hub;
use Symfony\Component\Mercure\PublisherInterface; use Symfony\Component\Mercure\HubInterface;
return [ return [
@ -21,14 +21,14 @@ return [
LcobucciJwtProvider::class => [ LcobucciJwtProvider::class => [
LazyServiceFactory::class, LazyServiceFactory::class,
], ],
Publisher::class => [ Hub::class => [
LazyServiceFactory::class, LazyServiceFactory::class,
], ],
], ],
'lazy_services' => [ 'lazy_services' => [
'class_map' => [ 'class_map' => [
LcobucciJwtProvider::class => LcobucciJwtProvider::class, LcobucciJwtProvider::class => LcobucciJwtProvider::class,
Publisher::class => PublisherInterface::class, Hub::class => HubInterface::class,
], ],
], ],
], ],

View file

@ -8,7 +8,7 @@ use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\EventDispatcherInterface;
use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use Symfony\Component\Mercure\Publisher; use Symfony\Component\Mercure\Hub;
return [ return [
@ -57,7 +57,7 @@ return [
Options\AppOptions::class, Options\AppOptions::class,
], ],
EventDispatcher\NotifyVisitToMercure::class => [ EventDispatcher\NotifyVisitToMercure::class => [
Publisher::class, Hub::class,
Mercure\MercureUpdatesGenerator::class, Mercure\MercureUpdatesGenerator::class,
'em', 'em',
'Logger_Shlink', 'Logger_Shlink',

View file

@ -9,7 +9,7 @@ use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated; use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface;
use Symfony\Component\Mercure\PublisherInterface; use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update; use Symfony\Component\Mercure\Update;
use Throwable; use Throwable;
@ -17,18 +17,18 @@ use function Functional\each;
class NotifyVisitToMercure class NotifyVisitToMercure
{ {
private PublisherInterface $publisher; private HubInterface $hub;
private MercureUpdatesGeneratorInterface $updatesGenerator; private MercureUpdatesGeneratorInterface $updatesGenerator;
private EntityManagerInterface $em; private EntityManagerInterface $em;
private LoggerInterface $logger; private LoggerInterface $logger;
public function __construct( public function __construct(
PublisherInterface $publisher, HubInterface $hub,
MercureUpdatesGeneratorInterface $updatesGenerator, MercureUpdatesGeneratorInterface $updatesGenerator,
EntityManagerInterface $em, EntityManagerInterface $em,
LoggerInterface $logger LoggerInterface $logger
) { ) {
$this->publisher = $publisher; $this->hub = $hub;
$this->em = $em; $this->em = $em;
$this->logger = $logger; $this->logger = $logger;
$this->updatesGenerator = $updatesGenerator; $this->updatesGenerator = $updatesGenerator;
@ -48,7 +48,7 @@ class NotifyVisitToMercure
} }
try { try {
each($this->determineUpdatesForVisit($visit), fn (Update $update) => ($this->publisher)($update)); each($this->determineUpdatesForVisit($visit), fn (Update $update) => $this->hub->publish($update));
} catch (Throwable $e) { } catch (Throwable $e) {
$this->logger->debug('Error while trying to notify mercure hub with new visit. {e}', [ $this->logger->debug('Error while trying to notify mercure hub with new visit. {e}', [
'e' => $e, 'e' => $e,

View file

@ -17,7 +17,7 @@ use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
use Shlinkio\Shlink\Core\EventDispatcher\NotifyVisitToMercure; use Shlinkio\Shlink\Core\EventDispatcher\NotifyVisitToMercure;
use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface;
use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Model\Visitor;
use Symfony\Component\Mercure\PublisherInterface; use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update; use Symfony\Component\Mercure\Update;
class NotifyVisitToMercureTest extends TestCase class NotifyVisitToMercureTest extends TestCase
@ -25,20 +25,20 @@ class NotifyVisitToMercureTest extends TestCase
use ProphecyTrait; use ProphecyTrait;
private NotifyVisitToMercure $listener; private NotifyVisitToMercure $listener;
private ObjectProphecy $publisher; private ObjectProphecy $hub;
private ObjectProphecy $updatesGenerator; private ObjectProphecy $updatesGenerator;
private ObjectProphecy $em; private ObjectProphecy $em;
private ObjectProphecy $logger; private ObjectProphecy $logger;
public function setUp(): void public function setUp(): void
{ {
$this->publisher = $this->prophesize(PublisherInterface::class); $this->hub = $this->prophesize(HubInterface::class);
$this->updatesGenerator = $this->prophesize(MercureUpdatesGeneratorInterface::class); $this->updatesGenerator = $this->prophesize(MercureUpdatesGeneratorInterface::class);
$this->em = $this->prophesize(EntityManagerInterface::class); $this->em = $this->prophesize(EntityManagerInterface::class);
$this->logger = $this->prophesize(LoggerInterface::class); $this->logger = $this->prophesize(LoggerInterface::class);
$this->listener = new NotifyVisitToMercure( $this->listener = new NotifyVisitToMercure(
$this->publisher->reveal(), $this->hub->reveal(),
$this->updatesGenerator->reveal(), $this->updatesGenerator->reveal(),
$this->em->reveal(), $this->em->reveal(),
$this->logger->reveal(), $this->logger->reveal(),
@ -60,7 +60,7 @@ class NotifyVisitToMercureTest extends TestCase
); );
$buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate(Argument::type(Visit::class)); $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate(Argument::type(Visit::class));
$buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate(Argument::type(Visit::class)); $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate(Argument::type(Visit::class));
$publish = $this->publisher->__invoke(Argument::type(Update::class)); $publish = $this->hub->publish(Argument::type(Update::class));
($this->listener)(new VisitLocated($visitId)); ($this->listener)(new VisitLocated($visitId));
@ -86,7 +86,7 @@ class NotifyVisitToMercureTest extends TestCase
$buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update); $buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update);
$buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update); $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update);
$buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update); $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update);
$publish = $this->publisher->__invoke($update); $publish = $this->hub->publish($update);
($this->listener)(new VisitLocated($visitId)); ($this->listener)(new VisitLocated($visitId));
@ -115,7 +115,7 @@ class NotifyVisitToMercureTest extends TestCase
$buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update); $buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update);
$buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update); $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update);
$buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update); $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update);
$publish = $this->publisher->__invoke($update)->willThrow($e); $publish = $this->hub->publish($update)->willThrow($e);
($this->listener)(new VisitLocated($visitId)); ($this->listener)(new VisitLocated($visitId));
@ -143,7 +143,7 @@ class NotifyVisitToMercureTest extends TestCase
$buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update); $buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update);
$buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update); $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update);
$buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update); $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update);
$publish = $this->publisher->__invoke($update); $publish = $this->hub->publish($update);
($this->listener)(new VisitLocated($visitId)); ($this->listener)(new VisitLocated($visitId));

View file

@ -3,3 +3,4 @@ parameters:
checkGenericClassInNonGenericObjectType: false checkGenericClassInNonGenericObjectType: false
ignoreErrors: ignoreErrors:
- '#If condition is always false#' - '#If condition is always false#'
- '#setOrderBy\(\) expects array\<int, string\>, array\<string, string\> given#'