2019-07-13 05:04:21 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2019-07-13 05:04:21 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shlinkio\Shlink\Core;
|
|
|
|
|
2020-01-01 14:11:53 -06:00
|
|
|
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
2019-12-28 06:07:11 -06:00
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
2022-09-18 03:01:22 -05:00
|
|
|
use Shlinkio\Shlink\CLI\GeoLite\GeolocationDbUpdater;
|
2022-07-26 03:17:50 -05:00
|
|
|
use Shlinkio\Shlink\Common\Cache\RedisPublishingHelper;
|
2022-07-26 05:17:37 -05:00
|
|
|
use Shlinkio\Shlink\Common\Mercure\MercureHubPublishingHelper;
|
2023-06-06 13:25:14 -05:00
|
|
|
use Shlinkio\Shlink\Common\Mercure\MercureOptions;
|
2022-07-24 03:12:26 -05:00
|
|
|
use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelper;
|
2023-11-15 12:57:58 -06:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
2022-09-23 07:50:26 -05:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocator;
|
|
|
|
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelper;
|
2023-06-03 10:56:52 -05:00
|
|
|
use Shlinkio\Shlink\EventDispatcher\Listener\EnabledListenerCheckerInterface;
|
2021-04-07 04:35:02 -05:00
|
|
|
use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater;
|
2023-06-03 10:56:52 -05:00
|
|
|
use Shlinkio\Shlink\IpGeolocation\GeoLite2\GeoLite2Options;
|
2019-08-10 06:56:06 -05:00
|
|
|
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
|
2019-07-13 05:04:21 -05:00
|
|
|
|
2023-11-15 12:57:58 -06:00
|
|
|
use function Shlinkio\Shlink\Config\runningInOpenswoole;
|
|
|
|
use function Shlinkio\Shlink\Config\runningInRoadRunner;
|
2019-07-13 05:04:21 -05:00
|
|
|
|
2023-11-15 12:57:58 -06:00
|
|
|
return (static function (): array {
|
|
|
|
$regularEvents = [
|
|
|
|
EventDispatcher\Event\UrlVisited::class => [
|
|
|
|
EventDispatcher\LocateVisit::class,
|
2019-12-28 06:50:41 -06:00
|
|
|
],
|
2023-11-15 12:57:58 -06:00
|
|
|
EventDispatcher\Event\GeoLiteDbCreated::class => [
|
|
|
|
EventDispatcher\LocateUnlocatedVisits::class,
|
2019-07-13 05:04:21 -05:00
|
|
|
],
|
2023-11-15 12:57:58 -06:00
|
|
|
];
|
|
|
|
$asyncEvents = [
|
|
|
|
EventDispatcher\Event\VisitLocated::class => [
|
|
|
|
EventDispatcher\Mercure\NotifyVisitToMercure::class,
|
|
|
|
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class,
|
|
|
|
EventDispatcher\RedisPubSub\NotifyVisitToRedis::class,
|
|
|
|
EventDispatcher\NotifyVisitToWebHooks::class,
|
|
|
|
EventDispatcher\UpdateGeoLiteDb::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\Event\ShortUrlCreated::class => [
|
|
|
|
EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class,
|
|
|
|
EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class,
|
|
|
|
EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
// Send visits to matomo asynchronously if the runtime allows it
|
|
|
|
if (runningInRoadRunner() || runningInOpenswoole()) {
|
|
|
|
$asyncEvents[EventDispatcher\Event\VisitLocated::class][] = EventDispatcher\Matomo\SendVisitToMatomo::class;
|
|
|
|
} else {
|
|
|
|
$regularEvents[EventDispatcher\Event\VisitLocated::class] = [EventDispatcher\Matomo\SendVisitToMatomo::class];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
'events' => [
|
|
|
|
'regular' => $regularEvents,
|
|
|
|
'async' => $asyncEvents,
|
2023-06-03 10:56:52 -05:00
|
|
|
],
|
|
|
|
|
2023-11-15 12:57:58 -06:00
|
|
|
'dependencies' => [
|
|
|
|
'factories' => [
|
|
|
|
EventDispatcher\LocateVisit::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\Matomo\SendVisitToMatomo::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\LocateUnlocatedVisits::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\NotifyVisitToWebHooks::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\Mercure\NotifyVisitToMercure::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\RedisPubSub\NotifyVisitToRedis::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => ConfigAbstractFactory::class,
|
|
|
|
EventDispatcher\UpdateGeoLiteDb::class => ConfigAbstractFactory::class,
|
|
|
|
|
|
|
|
EventDispatcher\Helper\EnabledListenerChecker::class => ConfigAbstractFactory::class,
|
|
|
|
],
|
|
|
|
|
|
|
|
'aliases' => [
|
|
|
|
EnabledListenerCheckerInterface::class => EventDispatcher\Helper\EnabledListenerChecker::class,
|
|
|
|
],
|
|
|
|
|
|
|
|
'delegators' => [
|
|
|
|
EventDispatcher\Mercure\NotifyVisitToMercure::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\RedisPubSub\NotifyVisitToRedis::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\LocateUnlocatedVisits::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\NotifyVisitToWebHooks::class => [
|
|
|
|
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
|
|
|
|
],
|
|
|
|
],
|
2019-07-13 08:43:54 -05:00
|
|
|
],
|
2020-04-11 11:00:29 -05:00
|
|
|
|
2023-11-15 12:57:58 -06:00
|
|
|
ConfigAbstractFactory::class => [
|
|
|
|
EventDispatcher\LocateVisit::class => [
|
|
|
|
IpLocationResolverInterface::class,
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
|
|
|
DbUpdater::class,
|
|
|
|
EventDispatcherInterface::class,
|
|
|
|
],
|
|
|
|
EventDispatcher\LocateUnlocatedVisits::class => [VisitLocator::class, VisitToLocationHelper::class],
|
|
|
|
EventDispatcher\NotifyVisitToWebHooks::class => [
|
|
|
|
'httpClient',
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
|
|
|
Options\WebhookOptions::class,
|
|
|
|
ShortUrl\Transformer\ShortUrlDataTransformer::class,
|
|
|
|
Options\AppOptions::class,
|
|
|
|
],
|
2022-07-21 13:07:28 -05:00
|
|
|
EventDispatcher\Mercure\NotifyVisitToMercure::class => [
|
2023-11-15 12:57:58 -06:00
|
|
|
MercureHubPublishingHelper::class,
|
|
|
|
EventDispatcher\PublishingUpdatesGenerator::class,
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
2021-04-07 04:35:02 -05:00
|
|
|
],
|
2022-07-24 12:00:48 -05:00
|
|
|
EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class => [
|
2023-11-15 12:57:58 -06:00
|
|
|
MercureHubPublishingHelper::class,
|
|
|
|
EventDispatcher\PublishingUpdatesGenerator::class,
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
2022-07-24 12:00:48 -05:00
|
|
|
],
|
2022-07-21 13:07:28 -05:00
|
|
|
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class => [
|
2023-11-15 12:57:58 -06:00
|
|
|
RabbitMqPublishingHelper::class,
|
|
|
|
EventDispatcher\PublishingUpdatesGenerator::class,
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
|
|
|
Visit\Transformer\OrphanVisitDataTransformer::class,
|
|
|
|
Options\RabbitMqOptions::class,
|
2021-12-11 14:04:16 -06:00
|
|
|
],
|
2022-07-24 03:18:19 -05:00
|
|
|
EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class => [
|
2023-11-15 12:57:58 -06:00
|
|
|
RabbitMqPublishingHelper::class,
|
|
|
|
EventDispatcher\PublishingUpdatesGenerator::class,
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
|
|
|
Options\RabbitMqOptions::class,
|
2022-07-24 03:18:19 -05:00
|
|
|
],
|
2022-07-25 11:23:13 -05:00
|
|
|
EventDispatcher\RedisPubSub\NotifyVisitToRedis::class => [
|
2023-11-15 12:57:58 -06:00
|
|
|
RedisPublishingHelper::class,
|
|
|
|
EventDispatcher\PublishingUpdatesGenerator::class,
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
|
|
|
'config.redis.pub_sub_enabled',
|
2022-07-25 11:23:13 -05:00
|
|
|
],
|
|
|
|
EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => [
|
2023-11-15 12:57:58 -06:00
|
|
|
RedisPublishingHelper::class,
|
|
|
|
EventDispatcher\PublishingUpdatesGenerator::class,
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
|
|
|
'config.redis.pub_sub_enabled',
|
2022-07-25 11:23:13 -05:00
|
|
|
],
|
2023-11-15 12:57:58 -06:00
|
|
|
|
|
|
|
EventDispatcher\Matomo\SendVisitToMatomo::class => [
|
|
|
|
'em',
|
|
|
|
'Logger_Shlink',
|
|
|
|
ShortUrlStringifier::class,
|
|
|
|
Matomo\MatomoOptions::class,
|
|
|
|
Matomo\MatomoTrackerBuilder::class,
|
2022-09-18 10:00:03 -05:00
|
|
|
],
|
2023-11-15 12:57:58 -06:00
|
|
|
|
|
|
|
EventDispatcher\UpdateGeoLiteDb::class => [
|
|
|
|
GeolocationDbUpdater::class,
|
|
|
|
'Logger_Shlink',
|
|
|
|
EventDispatcherInterface::class,
|
2020-04-11 11:00:29 -05:00
|
|
|
],
|
2023-06-03 10:56:52 -05:00
|
|
|
|
2023-11-15 12:57:58 -06:00
|
|
|
EventDispatcher\Helper\EnabledListenerChecker::class => [
|
|
|
|
Options\RabbitMqOptions::class,
|
|
|
|
'config.redis.pub_sub_enabled',
|
|
|
|
MercureOptions::class,
|
|
|
|
Options\WebhookOptions::class,
|
|
|
|
GeoLite2Options::class,
|
|
|
|
],
|
2023-06-03 10:56:52 -05:00
|
|
|
],
|
2019-07-13 05:04:21 -05:00
|
|
|
|
2023-11-15 12:57:58 -06:00
|
|
|
];
|
|
|
|
})();
|