From 582033ceb345a4bdd901af5bebcdf8518eab1025 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 16 Oct 2024 08:55:38 +0200 Subject: [PATCH] Migrate dev-specific configuration to env vars via .env file --- .gitignore | 1 + config/autoload/delete_short_urls.global.php | 20 ------ config/autoload/entity-manager.local.php.dist | 46 ------------- config/autoload/matomo.global.php | 16 ----- config/autoload/matomo.local.php.dist | 26 -------- config/autoload/mercure.global.php | 47 +++++++------- config/autoload/mercure.local.php.dist | 13 ---- config/autoload/qr-codes.global.php | 21 ------ config/autoload/rabbit.global.php | 1 + config/autoload/rabbit.local.php.dist | 15 ----- config/autoload/redirects.global.php | 20 ------ config/autoload/redis.local.php.local | 26 -------- config/autoload/robots.global.php | 14 ---- config/autoload/router.local.php.dist | 1 - config/autoload/tracking.global.php | 38 ----------- config/autoload/url-shortener.local.php.dist | 21 ------ docker-compose.yml | 12 +++- module/CLI/config/dependencies.config.php | 4 +- .../ShortUrl/CreateShortUrlCommand.php | 2 +- module/CLI/src/Factory/ApplicationFactory.php | 2 +- .../CLI/src/GeoLite/GeolocationDbUpdater.php | 2 +- module/CLI/src/Input/ShortUrlDataInput.php | 2 +- .../Domain/DomainRedirectsCommandTest.php | 2 +- .../Command/Domain/ListDomainsCommandTest.php | 2 +- .../ShortUrl/CreateShortUrlCommandTest.php | 2 +- .../test/Factory/ApplicationFactoryTest.php | 2 +- .../test/GeoLite/GeolocationDbUpdaterTest.php | 2 +- module/Core/config/dependencies.config.php | 53 ++++++++------- .../Core/config/event_dispatcher.config.php | 6 +- module/Core/src/Action/Model/QrCodeParams.php | 2 +- module/Core/src/Action/QrCodeAction.php | 2 +- module/Core/src/Action/RobotsAction.php | 2 +- .../src/{ => Config}/Options/AppOptions.php | 2 +- .../Config/Options/DeleteShortUrlsOptions.php | 28 ++++++++ .../Options/NotFoundRedirectOptions.php | 20 ++++-- .../{ => Config}/Options/QrCodeOptions.php | 21 +++++- .../src/Config/Options/RabbitMqOptions.php | 19 ++++++ .../{ => Config}/Options/RedirectOptions.php | 17 +++-- .../Core/src/Config/Options/RobotsOptions.php | 33 ++++++++++ .../src/Config/Options/TrackingOptions.php | 62 ++++++++++++++++++ .../Config/Options/UrlShortenerOptions.php | 62 ++++++++++++++++++ .../ErrorHandler/NotFoundRedirectHandler.php | 6 +- .../Helper/EnabledListenerChecker.php | 2 +- .../RabbitMq/NotifyNewShortUrlToRabbitMq.php | 2 +- .../RabbitMq/NotifyVisitToRabbitMq.php | 2 +- module/Core/src/Matomo/MatomoOptions.php | 26 ++++++-- .../src/Options/DeleteShortUrlsOptions.php | 16 ----- module/Core/src/Options/RabbitMqOptions.php | 13 ---- module/Core/src/Options/RobotsOptions.php | 22 ------- module/Core/src/Options/TrackingOptions.php | 33 ---------- .../Core/src/Options/UrlShortenerOptions.php | 36 ---------- .../src/ShortUrl/DeleteShortUrlService.php | 2 +- .../Helper/ShortCodeUniquenessHelper.php | 2 +- .../Helper/ShortUrlRedirectionBuilder.php | 2 +- .../Helper/ShortUrlTitleResolutionHelper.php | 2 +- .../ExtraPathRedirectMiddleware.php | 2 +- .../TrimTrailingSlashMiddleware.php | 2 +- .../src/ShortUrl/Model/ShortUrlCreation.php | 2 +- .../Model/Validation/CustomSlugFilter.php | 2 +- .../Model/Validation/CustomSlugValidator.php | 2 +- .../Model/Validation/ShortUrlInputFilter.php | 2 +- .../PersistenceShortUrlRelationResolver.php | 2 +- .../Core/src/ShortUrl/ShortUrlListService.php | 2 +- module/Core/src/ShortUrl/ShortUrlResolver.php | 2 +- .../Core/src/Util/RedirectResponseHelper.php | 2 +- module/Core/src/Visit/Model/Visitor.php | 2 +- module/Core/src/Visit/RequestTracker.php | 2 +- module/Core/src/Visit/VisitsTracker.php | 2 +- module/Core/test/Action/QrCodeActionTest.php | 2 +- module/Core/test/Action/RobotsActionTest.php | 2 +- .../Config/NotFoundRedirectResolverTest.php | 2 +- .../NotFoundRedirectHandlerTest.php | 2 +- .../Helper/EnabledListenerCheckerTest.php | 2 +- .../NotifyNewShortUrlToRabbitMqTest.php | 2 +- .../RabbitMq/NotifyVisitToRabbitMqTest.php | 2 +- .../ShortUrl/DeleteShortUrlServiceTest.php | 2 +- .../test/ShortUrl/Entity/ShortUrlTest.php | 2 +- .../Helper/ShortCodeUniquenessHelperTest.php | 2 +- .../Helper/ShortUrlRedirectionBuilderTest.php | 2 +- .../ShortUrlTitleResolutionHelperTest.php | 2 +- .../ExtraPathRedirectMiddlewareTest.php | 2 +- .../TrimTrailingSlashMiddlewareTest.php | 2 +- .../ShortUrl/Model/ShortUrlCreationTest.php | 2 +- .../Validation/CustomSlugValidatorTest.php | 2 +- ...ersistenceShortUrlRelationResolverTest.php | 2 +- .../test/ShortUrl/ShortUrlListServiceTest.php | 2 +- .../test/ShortUrl/ShortUrlResolverTest.php | 2 +- .../test/Util/RedirectResponseHelperTest.php | 2 +- module/Core/test/Visit/Model/VisitorTest.php | 2 +- module/Core/test/Visit/RequestTrackerTest.php | 2 +- module/Core/test/Visit/VisitsTrackerTest.php | 2 +- module/Rest/config/dependencies.config.php | 10 +-- .../src/Action/Domain/ListDomainsAction.php | 2 +- module/Rest/src/Action/HealthAction.php | 2 +- .../ShortUrl/AbstractCreateShortUrlAction.php | 2 +- .../Action/Domain/ListDomainsActionTest.php | 2 +- .../Request/DomainRedirectsRequestTest.php | 2 +- module/Rest/test/Action/HealthActionTest.php | 2 +- .../ShortUrl/CreateShortUrlActionTest.php | 2 +- .../SingleStepCreateShortUrlActionTest.php | 2 +- shlink-dev.env | 65 +++++++++++++++++++ 101 files changed, 475 insertions(+), 543 deletions(-) delete mode 100644 config/autoload/delete_short_urls.global.php delete mode 100644 config/autoload/entity-manager.local.php.dist delete mode 100644 config/autoload/matomo.global.php delete mode 100644 config/autoload/matomo.local.php.dist delete mode 100644 config/autoload/mercure.local.php.dist delete mode 100644 config/autoload/qr-codes.global.php delete mode 100644 config/autoload/rabbit.local.php.dist delete mode 100644 config/autoload/redirects.global.php delete mode 100644 config/autoload/redis.local.php.local delete mode 100644 config/autoload/robots.global.php delete mode 100644 config/autoload/tracking.global.php delete mode 100644 config/autoload/url-shortener.local.php.dist rename module/Core/src/{ => Config}/Options/AppOptions.php (86%) create mode 100644 module/Core/src/Config/Options/DeleteShortUrlsOptions.php rename module/Core/src/{ => Config}/Options/NotFoundRedirectOptions.php (54%) rename module/Core/src/{ => Config}/Options/QrCodeOptions.php (54%) create mode 100644 module/Core/src/Config/Options/RabbitMqOptions.php rename module/Core/src/{ => Config}/Options/RedirectOptions.php (59%) create mode 100644 module/Core/src/Config/Options/RobotsOptions.php create mode 100644 module/Core/src/Config/Options/TrackingOptions.php create mode 100644 module/Core/src/Config/Options/UrlShortenerOptions.php delete mode 100644 module/Core/src/Options/DeleteShortUrlsOptions.php delete mode 100644 module/Core/src/Options/RabbitMqOptions.php delete mode 100644 module/Core/src/Options/RobotsOptions.php delete mode 100644 module/Core/src/Options/TrackingOptions.php delete mode 100644 module/Core/src/Options/UrlShortenerOptions.php create mode 100644 shlink-dev.env diff --git a/.gitignore b/.gitignore index 04c8ed56..e539b609 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ docs/mercure.html docker-compose.override.yml .phpunit.result.cache docs/swagger/swagger-inlined.json +shlink-dev.local.env diff --git a/config/autoload/delete_short_urls.global.php b/config/autoload/delete_short_urls.global.php deleted file mode 100644 index 2d203ea1..00000000 --- a/config/autoload/delete_short_urls.global.php +++ /dev/null @@ -1,20 +0,0 @@ -loadFromEnv(); - - return [ - - 'delete_short_urls' => [ - 'check_visits_threshold' => $threshold !== null, - 'visits_threshold' => (int) ($threshold ?? DEFAULT_DELETE_SHORT_URL_THRESHOLD), - ], - - ]; -})(); diff --git a/config/autoload/entity-manager.local.php.dist b/config/autoload/entity-manager.local.php.dist deleted file mode 100644 index abe5dd87..00000000 --- a/config/autoload/entity-manager.local.php.dist +++ /dev/null @@ -1,46 +0,0 @@ - [ - 'connection' => [ - // MySQL - 'user' => 'root', - 'password' => 'root', - 'driver' => 'pdo_mysql', - 'host' => 'shlink_db_mysql', - 'dbname' => 'shlink', -// 'dbname' => 'shlink_foo', - 'charset' => 'utf8mb4', - - // MariaDB -// 'user' => 'root', -// 'password' => 'root', -// 'driver' => 'pdo_mysql', -// 'host' => 'shlink_db_maria', -// 'dbname' => 'shlink_foo', -// 'charset' => 'utf8mb4', - - // Postgres -// 'user' => 'postgres', -// 'password' => 'root', -// 'driver' => 'pdo_pgsql', -// 'host' => 'shlink_db_postgres', -// 'dbname' => 'shlink_foo', -// 'charset' => 'utf8', - - // MSSQL -// 'user' => 'sa', -// 'password' => 'Passw0rd!', -// 'driver' => 'pdo_sqlsrv', -// 'host' => 'shlink_db_ms', -// 'dbname' => 'shlink_foo', -// 'driverOptions' => [ -// 'TrustServerCertificate' => 'true', -// ], - ], - ], - -]; diff --git a/config/autoload/matomo.global.php b/config/autoload/matomo.global.php deleted file mode 100644 index d7369ea7..00000000 --- a/config/autoload/matomo.global.php +++ /dev/null @@ -1,16 +0,0 @@ - [ - 'enabled' => (bool) EnvVars::MATOMO_ENABLED->loadFromEnv(), - 'base_url' => EnvVars::MATOMO_BASE_URL->loadFromEnv(), - 'site_id' => EnvVars::MATOMO_SITE_ID->loadFromEnv(), - 'api_token' => EnvVars::MATOMO_API_TOKEN->loadFromEnv(), - ], - -]; diff --git a/config/autoload/matomo.local.php.dist b/config/autoload/matomo.local.php.dist deleted file mode 100644 index 2a940407..00000000 --- a/config/autoload/matomo.local.php.dist +++ /dev/null @@ -1,26 +0,0 @@ - [ -// 'enabled' => true, -// 'base_url' => 'http://shlink_matomo', -// 'site_id' => '...', -// 'api_token' => '...', - ], - -]; diff --git a/config/autoload/mercure.global.php b/config/autoload/mercure.global.php index c50e1f8e..83abed1a 100644 --- a/config/autoload/mercure.global.php +++ b/config/autoload/mercure.global.php @@ -8,34 +8,31 @@ use Shlinkio\Shlink\Core\Config\EnvVars; use Symfony\Component\Mercure\Hub; use Symfony\Component\Mercure\HubInterface; -return (static function (): array { - $publicUrl = EnvVars::MERCURE_PUBLIC_HUB_URL->loadFromEnv(); +return [ - return [ + // This config is used by shlink-common. Do not delete + 'mercure' => [ + 'public_hub_url' => EnvVars::MERCURE_PUBLIC_HUB_URL->loadFromEnv(), + 'internal_hub_url' => EnvVars::MERCURE_INTERNAL_HUB_URL->loadFromEnv(), + 'jwt_secret' => EnvVars::MERCURE_JWT_SECRET->loadFromEnv(), + 'jwt_issuer' => 'Shlink', + ], - 'mercure' => [ - 'public_hub_url' => $publicUrl, - 'internal_hub_url' => EnvVars::MERCURE_INTERNAL_HUB_URL->loadFromEnv(), - 'jwt_secret' => EnvVars::MERCURE_JWT_SECRET->loadFromEnv(), - 'jwt_issuer' => 'Shlink', - ], - - 'dependencies' => [ - 'delegators' => [ - LcobucciJwtProvider::class => [ - LazyServiceFactory::class, - ], - Hub::class => [ - LazyServiceFactory::class, - ], + 'dependencies' => [ + 'delegators' => [ + LcobucciJwtProvider::class => [ + LazyServiceFactory::class, ], - 'lazy_services' => [ - 'class_map' => [ - LcobucciJwtProvider::class => LcobucciJwtProvider::class, - Hub::class => HubInterface::class, - ], + Hub::class => [ + LazyServiceFactory::class, ], ], + 'lazy_services' => [ + 'class_map' => [ + LcobucciJwtProvider::class => LcobucciJwtProvider::class, + Hub::class => HubInterface::class, + ], + ], + ], - ]; -})(); +]; diff --git a/config/autoload/mercure.local.php.dist b/config/autoload/mercure.local.php.dist deleted file mode 100644 index 13a74022..00000000 --- a/config/autoload/mercure.local.php.dist +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'public_hub_url' => 'http://localhost:8002', - 'internal_hub_url' => 'http://shlink_mercure_proxy', - 'jwt_secret' => 'mercure_jwt_key_long_enough_to_avoid_error', - ], - -]; diff --git a/config/autoload/qr-codes.global.php b/config/autoload/qr-codes.global.php deleted file mode 100644 index 23caadf2..00000000 --- a/config/autoload/qr-codes.global.php +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'size' => (int) EnvVars::DEFAULT_QR_CODE_SIZE->loadFromEnv(), - 'margin' => (int) EnvVars::DEFAULT_QR_CODE_MARGIN->loadFromEnv(), - 'format' => EnvVars::DEFAULT_QR_CODE_FORMAT->loadFromEnv(), - 'error_correction' => EnvVars::DEFAULT_QR_CODE_ERROR_CORRECTION->loadFromEnv(), - 'round_block_size' => (bool) EnvVars::DEFAULT_QR_CODE_ROUND_BLOCK_SIZE->loadFromEnv(), - 'enabled_for_disabled_short_urls' => (bool) EnvVars::QR_CODE_FOR_DISABLED_SHORT_URLS->loadFromEnv(), - 'color' => EnvVars::DEFAULT_QR_CODE_COLOR->loadFromEnv(), - 'bg_color' => EnvVars::DEFAULT_QR_CODE_BG_COLOR->loadFromEnv(), - 'logo_url' => EnvVars::DEFAULT_QR_CODE_LOGO_URL->loadFromEnv(), - ], - -]; diff --git a/config/autoload/rabbit.global.php b/config/autoload/rabbit.global.php index 86e2dd6a..c9532377 100644 --- a/config/autoload/rabbit.global.php +++ b/config/autoload/rabbit.global.php @@ -6,6 +6,7 @@ use Shlinkio\Shlink\Core\Config\EnvVars; return [ + // This config is used by shlink-common. Do not delete 'rabbitmq' => [ 'enabled' => (bool) EnvVars::RABBITMQ_ENABLED->loadFromEnv(), 'host' => EnvVars::RABBITMQ_HOST->loadFromEnv(), diff --git a/config/autoload/rabbit.local.php.dist b/config/autoload/rabbit.local.php.dist deleted file mode 100644 index 37faf181..00000000 --- a/config/autoload/rabbit.local.php.dist +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'enabled' => true, - 'host' => 'shlink_rabbitmq', - 'port' => 5672, - 'user' => 'rabbit', - 'password' => 'rabbit', - ], - -]; diff --git a/config/autoload/redirects.global.php b/config/autoload/redirects.global.php deleted file mode 100644 index dbf026db..00000000 --- a/config/autoload/redirects.global.php +++ /dev/null @@ -1,20 +0,0 @@ - [ - 'invalid_short_url' => EnvVars::DEFAULT_INVALID_SHORT_URL_REDIRECT->loadFromEnv(), - 'regular_404' => EnvVars::DEFAULT_REGULAR_404_REDIRECT->loadFromEnv(), - 'base_url' => EnvVars::DEFAULT_BASE_URL_REDIRECT->loadFromEnv(), - ], - - 'redirects' => [ - 'redirect_status_code' => (int) EnvVars::REDIRECT_STATUS_CODE->loadFromEnv(), - 'redirect_cache_lifetime' => (int) EnvVars::REDIRECT_CACHE_LIFETIME->loadFromEnv(), - ], - -]; diff --git a/config/autoload/redis.local.php.local b/config/autoload/redis.local.php.local deleted file mode 100644 index 7fd57112..00000000 --- a/config/autoload/redis.local.php.local +++ /dev/null @@ -1,26 +0,0 @@ - [ - 'redis' => [ - 'servers' => 'tcp://shlink_redis:6379', -// 'servers' => 'tcp://barbar@shlink_redis_acl:6379', -// 'servers' => 'tcp://foo:bar@shlink_redis_acl:6379', - ], - ], - - 'redis' => [ - 'pub_sub_enabled' => true, - ], - - 'dependencies' => [ - 'aliases' => [ - // With this config, a user could alias 'lock_store' => 'redis_lock_store' to override the default -// 'lock_store' => 'redis_lock_store', - ], - ], - -]; diff --git a/config/autoload/robots.global.php b/config/autoload/robots.global.php deleted file mode 100644 index 35235d72..00000000 --- a/config/autoload/robots.global.php +++ /dev/null @@ -1,14 +0,0 @@ - [ - 'allow-all-short-urls' => (bool) Config\EnvVars::ROBOTS_ALLOW_ALL_SHORT_URLS->loadFromEnv(), - 'user-agents' => splitByComma(Config\EnvVars::ROBOTS_USER_AGENTS->loadFromEnv()), - ], - -]; diff --git a/config/autoload/router.local.php.dist b/config/autoload/router.local.php.dist index 39bd7169..dc67b587 100644 --- a/config/autoload/router.local.php.dist +++ b/config/autoload/router.local.php.dist @@ -7,7 +7,6 @@ use Mezzio\Router\FastRouteRouter; return [ 'router' => [ -// 'base_path' => '', 'fastroute' => [ FastRouteRouter::CONFIG_CACHE_ENABLED => false, ], diff --git a/config/autoload/tracking.global.php b/config/autoload/tracking.global.php deleted file mode 100644 index 713a209e..00000000 --- a/config/autoload/tracking.global.php +++ /dev/null @@ -1,38 +0,0 @@ - [ - // Tells if IP addresses should be anonymized before persisting, to fulfil data protection regulations - // This applies only if IP address tracking is enabled - 'anonymize_remote_addr' => (bool) EnvVars::ANONYMIZE_REMOTE_ADDR->loadFromEnv(), - - // Tells if visits to not-found URLs should be tracked. The disable_tracking option takes precedence - 'track_orphan_visits' => (bool) EnvVars::TRACK_ORPHAN_VISITS->loadFromEnv(), - - // A query param that, if provided, will disable tracking of one particular visit. Always takes precedence - 'disable_track_param' => EnvVars::DISABLE_TRACK_PARAM->loadFromEnv(), - - // If true, visits will not be tracked at all - 'disable_tracking' => (bool) EnvVars::DISABLE_TRACKING->loadFromEnv(), - - // If true, visits will be tracked, but neither the IP address, nor the location will be resolved - 'disable_ip_tracking' => (bool) EnvVars::DISABLE_IP_TRACKING->loadFromEnv(), - - // If true, the referrer will not be tracked - 'disable_referrer_tracking' => (bool) EnvVars::DISABLE_REFERRER_TRACKING->loadFromEnv(), - - // If true, the user agent will not be tracked - 'disable_ua_tracking' => (bool) EnvVars::DISABLE_UA_TRACKING->loadFromEnv(), - - // A list of IP addresses, patterns or CIDR blocks from which tracking is disabled by default - 'disable_tracking_from' => splitByComma(EnvVars::DISABLE_TRACKING_FROM->loadFromEnv()), - ], - -]; diff --git a/config/autoload/url-shortener.local.php.dist b/config/autoload/url-shortener.local.php.dist deleted file mode 100644 index 715d2822..00000000 --- a/config/autoload/url-shortener.local.php.dist +++ /dev/null @@ -1,21 +0,0 @@ - [ - 'domain' => [ - 'schema' => 'http', - 'hostname' => sprintf('localhost:%s', match (true) { - runningInRoadRunner() => '8800', - default => '8000', - }), - ], -// 'multi_segment_slugs_enabled' => true, -// 'trailing_slash_enabled' => true, - ], - -]; diff --git a/docker-compose.yml b/docker-compose.yml index 41f54cba..718ba4c1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,7 +33,11 @@ services: - shlink_rabbitmq - shlink_matomo environment: - LC_ALL: C + DEFAULT_DOMAIN: localhost:8000 + env_file: + - path: shlink-dev.env + - path: shlink-dev.local.env + required: false extra_hosts: - 'host.docker.internal:host-gateway' @@ -59,7 +63,11 @@ services: - shlink_rabbitmq - shlink_matomo environment: - LC_ALL: C + DEFAULT_DOMAIN: localhost:8800 + env_file: + - path: shlink-dev.env + - path: shlink-dev.local.env + required: false extra_hosts: - 'host.docker.internal:host-gateway' diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php index 0ee1a331..fd26a5bc 100644 --- a/module/CLI/config/dependencies.config.php +++ b/module/CLI/config/dependencies.config.php @@ -7,10 +7,10 @@ namespace Shlinkio\Shlink\CLI; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Laminas\ServiceManager\Factory\InvokableFactory; use Shlinkio\Shlink\Common\Doctrine\NoDbNameConnectionFactory; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Domain\DomainService; use Shlinkio\Shlink\Core\Matomo; -use Shlinkio\Shlink\Core\Options\TrackingOptions; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\RedirectRule\ShortUrlRedirectRuleService; use Shlinkio\Shlink\Core\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; diff --git a/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php index 0273da71..fdff2ddc 100644 --- a/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php @@ -6,8 +6,8 @@ namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Input\ShortUrlDataInput; use Shlinkio\Shlink\CLI\Util\ExitCode; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\ShortUrl\UrlShortenerInterface; use Symfony\Component\Console\Command\Command; diff --git a/module/CLI/src/Factory/ApplicationFactory.php b/module/CLI/src/Factory/ApplicationFactory.php index ab716f7e..89cf4271 100644 --- a/module/CLI/src/Factory/ApplicationFactory.php +++ b/module/CLI/src/Factory/ApplicationFactory.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Factory; use Psr\Container\ContainerInterface; -use Shlinkio\Shlink\Core\Options\AppOptions; +use Shlinkio\Shlink\Core\Config\Options\AppOptions; use Symfony\Component\Console\Application as CliApp; use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; diff --git a/module/CLI/src/GeoLite/GeolocationDbUpdater.php b/module/CLI/src/GeoLite/GeolocationDbUpdater.php index ff42c930..85ae1d3a 100644 --- a/module/CLI/src/GeoLite/GeolocationDbUpdater.php +++ b/module/CLI/src/GeoLite/GeolocationDbUpdater.php @@ -9,7 +9,7 @@ use Closure; use GeoIp2\Database\Reader; use MaxMind\Db\Reader\Metadata; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; -use Shlinkio\Shlink\Core\Options\TrackingOptions; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\IpGeolocation\Exception\DbUpdateException; use Shlinkio\Shlink\IpGeolocation\Exception\MissingLicenseException; use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; diff --git a/module/CLI/src/Input/ShortUrlDataInput.php b/module/CLI/src/Input/ShortUrlDataInput.php index 10c2da7c..2d3bf91e 100644 --- a/module/CLI/src/Input/ShortUrlDataInput.php +++ b/module/CLI/src/Input/ShortUrlDataInput.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Input; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlEdition; use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter; diff --git a/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php b/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php index 0bc77aca..32240fc5 100644 --- a/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php +++ b/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php @@ -10,10 +10,10 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Domain\DomainRedirectsCommand; use Shlinkio\Shlink\Core\Config\NotFoundRedirects; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Model\DomainItem; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; use Symfony\Component\Console\Tester\CommandTester; diff --git a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php index cfa09e18..2621f940 100644 --- a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php +++ b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php @@ -11,10 +11,10 @@ use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand; use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Config\NotFoundRedirects; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Model\DomainItem; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; use Symfony\Component\Console\Tester\CommandTester; diff --git a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php index 33031c6b..86bd87fb 100644 --- a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php @@ -12,8 +12,8 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\ShortUrl\CreateShortUrlCommand; use Shlinkio\Shlink\CLI\Util\ExitCode; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; diff --git a/module/CLI/test/Factory/ApplicationFactoryTest.php b/module/CLI/test/Factory/ApplicationFactoryTest.php index 83b0fc66..88b1280b 100644 --- a/module/CLI/test/Factory/ApplicationFactoryTest.php +++ b/module/CLI/test/Factory/ApplicationFactoryTest.php @@ -8,7 +8,7 @@ use Laminas\ServiceManager\ServiceManager; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Factory\ApplicationFactory; -use Shlinkio\Shlink\Core\Options\AppOptions; +use Shlinkio\Shlink\Core\Config\Options\AppOptions; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; class ApplicationFactoryTest extends TestCase diff --git a/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php index cbb4af5c..3b0f452e 100644 --- a/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\GeoLite\GeolocationDbUpdater; use Shlinkio\Shlink\CLI\GeoLite\GeolocationResult; -use Shlinkio\Shlink\Core\Options\TrackingOptions; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\IpGeolocation\Exception\DbUpdateException; use Shlinkio\Shlink\IpGeolocation\Exception\MissingLicenseException; use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface; diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index 8f8b609b..f50469c0 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -9,7 +9,7 @@ use Laminas\ServiceManager\Factory\InvokableFactory; use Psr\EventDispatcher\EventDispatcherInterface; use Shlinkio\Shlink\Common\Doctrine\EntityRepositoryFactory; use Shlinkio\Shlink\Config\Factory\ValinorConfigFactory; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; use Shlinkio\Shlink\Importer\ImportedLinksProcessorInterface; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; @@ -24,15 +24,15 @@ return [ ErrorHandler\NotFoundRedirectHandler::class => ConfigAbstractFactory::class, ErrorHandler\NotFoundTemplateHandler::class => InvokableFactory::class, - Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'], - Options\DeleteShortUrlsOptions::class => [ValinorConfigFactory::class, 'config.delete_short_urls'], - Options\NotFoundRedirectOptions::class => [ValinorConfigFactory::class, 'config.not_found_redirects'], - Options\RedirectOptions::class => [ValinorConfigFactory::class, 'config.redirects'], - Options\UrlShortenerOptions::class => [ValinorConfigFactory::class, 'config.url_shortener'], - Options\TrackingOptions::class => [ValinorConfigFactory::class, 'config.tracking'], - Options\QrCodeOptions::class => [ValinorConfigFactory::class, 'config.qr_codes'], - Options\RabbitMqOptions::class => [ValinorConfigFactory::class, 'config.rabbitmq'], - Options\RobotsOptions::class => [ValinorConfigFactory::class, 'config.robots'], + Config\Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'], + Config\Options\DeleteShortUrlsOptions::class => [Config\Options\DeleteShortUrlsOptions::class, 'fromEnv'], + Config\Options\NotFoundRedirectOptions::class => [Config\Options\NotFoundRedirectOptions::class, 'fromEnv'], + Config\Options\RedirectOptions::class => [Config\Options\RedirectOptions::class, 'fromEnv'], + Config\Options\UrlShortenerOptions::class => [Config\Options\UrlShortenerOptions::class, 'fromEnv'], + Config\Options\TrackingOptions::class => [Config\Options\TrackingOptions::class, 'fromEnv'], + Config\Options\QrCodeOptions::class => [Config\Options\QrCodeOptions::class, 'fromEnv'], + Config\Options\RabbitMqOptions::class => [Config\Options\RabbitMqOptions::class, 'fromEnv'], + Config\Options\RobotsOptions::class => [Config\Options\RobotsOptions::class, 'fromEnv'], RedirectRule\ShortUrlRedirectRuleService::class => ConfigAbstractFactory::class, RedirectRule\ShortUrlRedirectionResolver::class => ConfigAbstractFactory::class, @@ -101,7 +101,7 @@ return [ Crawling\CrawlingHelper::class => ConfigAbstractFactory::class, - Matomo\MatomoOptions::class => [ValinorConfigFactory::class, 'config.matomo'], + Matomo\MatomoOptions::class => [Matomo\MatomoOptions::class, 'fromEnv'], Matomo\MatomoTrackerBuilder::class => ConfigAbstractFactory::class, Matomo\MatomoVisitSender::class => ConfigAbstractFactory::class, ], @@ -137,9 +137,9 @@ return [ Visit\VisitsTracker::class => [ 'em', EventDispatcherInterface::class, - Options\TrackingOptions::class, + Config\Options\TrackingOptions::class, ], - Visit\RequestTracker::class => [Visit\VisitsTracker::class, Options\TrackingOptions::class], + Visit\RequestTracker::class => [Visit\VisitsTracker::class, Config\Options\TrackingOptions::class], Visit\VisitsDeleter::class => [Visit\Repository\VisitDeleterRepository::class], ShortUrl\ShortUrlService::class => [ 'em', @@ -149,7 +149,7 @@ return [ ], ShortUrl\ShortUrlListService::class => [ ShortUrl\Repository\ShortUrlListRepository::class, - Options\UrlShortenerOptions::class, + Config\Options\UrlShortenerOptions::class, ], Visit\Geolocation\VisitLocator::class => ['em', Visit\Repository\VisitIterationRepository::class], Visit\Geolocation\VisitToLocationHelper::class => [IpLocationResolverInterface::class], @@ -157,20 +157,20 @@ return [ Tag\TagService::class => ['em'], ShortUrl\DeleteShortUrlService::class => [ 'em', - Options\DeleteShortUrlsOptions::class, + Config\Options\DeleteShortUrlsOptions::class, ShortUrl\ShortUrlResolver::class, ShortUrl\Repository\ExpiredShortUrlsRepository::class, ], - ShortUrl\ShortUrlResolver::class => ['em', Options\UrlShortenerOptions::class], + ShortUrl\ShortUrlResolver::class => ['em', Config\Options\UrlShortenerOptions::class], ShortUrl\ShortUrlVisitsDeleter::class => [ Visit\Repository\VisitDeleterRepository::class, ShortUrl\ShortUrlResolver::class, ], - ShortUrl\Helper\ShortCodeUniquenessHelper::class => ['em', Options\UrlShortenerOptions::class], + ShortUrl\Helper\ShortCodeUniquenessHelper::class => ['em', Config\Options\UrlShortenerOptions::class], Domain\DomainService::class => ['em', 'config.url_shortener.domain.hostname'], Util\DoctrineBatchHelper::class => ['em'], - Util\RedirectResponseHelper::class => [Options\RedirectOptions::class], + Util\RedirectResponseHelper::class => [Config\Options\RedirectOptions::class], Config\NotFoundRedirectResolver::class => [Util\RedirectResponseHelper::class, 'Logger_Shlink'], @@ -188,19 +188,22 @@ return [ ShortUrl\ShortUrlResolver::class, ShortUrl\Helper\ShortUrlStringifier::class, 'Logger_Shlink', - Options\QrCodeOptions::class, + Config\Options\QrCodeOptions::class, ], - Action\RobotsAction::class => [Crawling\CrawlingHelper::class, Options\RobotsOptions::class], + Action\RobotsAction::class => [Crawling\CrawlingHelper::class, Config\Options\RobotsOptions::class], ShortUrl\Resolver\PersistenceShortUrlRelationResolver::class => [ 'em', - Options\UrlShortenerOptions::class, + Config\Options\UrlShortenerOptions::class, Lock\LockFactory::class, ], ShortUrl\Helper\ShortUrlStringifier::class => ['config.url_shortener.domain', 'config.router.base_path'], - ShortUrl\Helper\ShortUrlTitleResolutionHelper::class => ['httpClient', Options\UrlShortenerOptions::class], + ShortUrl\Helper\ShortUrlTitleResolutionHelper::class => [ + 'httpClient', + Config\Options\UrlShortenerOptions::class, + ], ShortUrl\Helper\ShortUrlRedirectionBuilder::class => [ - Options\TrackingOptions::class, + Config\Options\TrackingOptions::class, RedirectRule\ShortUrlRedirectionResolver::class, ], ShortUrl\Transformer\ShortUrlDataTransformer::class => [ShortUrl\Helper\ShortUrlStringifier::class], @@ -209,9 +212,9 @@ return [ Visit\RequestTracker::class, ShortUrl\Helper\ShortUrlRedirectionBuilder::class, Util\RedirectResponseHelper::class, - Options\UrlShortenerOptions::class, + Config\Options\UrlShortenerOptions::class, ], - ShortUrl\Middleware\TrimTrailingSlashMiddleware::class => [Options\UrlShortenerOptions::class], + ShortUrl\Middleware\TrimTrailingSlashMiddleware::class => [Config\Options\UrlShortenerOptions::class], EventDispatcher\PublishingUpdatesGenerator::class => [ShortUrl\Transformer\ShortUrlDataTransformer::class], diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index f401f255..2491d606 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -129,14 +129,14 @@ return (static function (): array { EventDispatcher\PublishingUpdatesGenerator::class, 'em', 'Logger_Shlink', - Options\RabbitMqOptions::class, + Config\Options\RabbitMqOptions::class, ], EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class => [ RabbitMqPublishingHelper::class, EventDispatcher\PublishingUpdatesGenerator::class, 'em', 'Logger_Shlink', - Options\RabbitMqOptions::class, + Config\Options\RabbitMqOptions::class, ], EventDispatcher\RedisPubSub\NotifyVisitToRedis::class => [ RedisPublishingHelper::class, @@ -167,7 +167,7 @@ return (static function (): array { ], EventDispatcher\Helper\EnabledListenerChecker::class => [ - Options\RabbitMqOptions::class, + Config\Options\RabbitMqOptions::class, 'config.redis.pub_sub_enabled', MercureOptions::class, GeoLite2Options::class, diff --git a/module/Core/src/Action/Model/QrCodeParams.php b/module/Core/src/Action/Model/QrCodeParams.php index 2a3907cc..46d90056 100644 --- a/module/Core/src/Action/Model/QrCodeParams.php +++ b/module/Core/src/Action/Model/QrCodeParams.php @@ -12,7 +12,7 @@ use Endroid\QrCode\Writer\PngWriter; use Endroid\QrCode\Writer\SvgWriter; use Endroid\QrCode\Writer\WriterInterface; use Psr\Http\Message\ServerRequestInterface; -use Shlinkio\Shlink\Core\Options\QrCodeOptions; +use Shlinkio\Shlink\Core\Config\Options\QrCodeOptions; use function ctype_xdigit; use function hexdec; diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index 4da8bb32..607fab50 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -13,8 +13,8 @@ use Psr\Http\Server\RequestHandlerInterface; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\Response\QrCodeResponse; use Shlinkio\Shlink\Core\Action\Model\QrCodeParams; +use Shlinkio\Shlink\Core\Config\Options\QrCodeOptions; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; -use Shlinkio\Shlink\Core\Options\QrCodeOptions; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface; diff --git a/module/Core/src/Action/RobotsAction.php b/module/Core/src/Action/RobotsAction.php index 29c2c8d2..21b7d21e 100644 --- a/module/Core/src/Action/RobotsAction.php +++ b/module/Core/src/Action/RobotsAction.php @@ -9,8 +9,8 @@ use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; +use Shlinkio\Shlink\Core\Config\Options\RobotsOptions; use Shlinkio\Shlink\Core\Crawling\CrawlingHelperInterface; -use Shlinkio\Shlink\Core\Options\RobotsOptions; use function sprintf; diff --git a/module/Core/src/Options/AppOptions.php b/module/Core/src/Config/Options/AppOptions.php similarity index 86% rename from module/Core/src/Options/AppOptions.php rename to module/Core/src/Config/Options/AppOptions.php index ec545352..42f07642 100644 --- a/module/Core/src/Options/AppOptions.php +++ b/module/Core/src/Config/Options/AppOptions.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Shlinkio\Shlink\Core\Options; +namespace Shlinkio\Shlink\Core\Config\Options; use function sprintf; diff --git a/module/Core/src/Config/Options/DeleteShortUrlsOptions.php b/module/Core/src/Config/Options/DeleteShortUrlsOptions.php new file mode 100644 index 00000000..97916d36 --- /dev/null +++ b/module/Core/src/Config/Options/DeleteShortUrlsOptions.php @@ -0,0 +1,28 @@ +loadFromEnv(); + + return new self( + visitsThreshold: (int) ($threshold ?? DEFAULT_DELETE_SHORT_URL_THRESHOLD), + checkVisitsThreshold: $threshold !== null, + ); + } +} diff --git a/module/Core/src/Options/NotFoundRedirectOptions.php b/module/Core/src/Config/Options/NotFoundRedirectOptions.php similarity index 54% rename from module/Core/src/Options/NotFoundRedirectOptions.php rename to module/Core/src/Config/Options/NotFoundRedirectOptions.php index fe99ac7e..e6ef6a24 100644 --- a/module/Core/src/Options/NotFoundRedirectOptions.php +++ b/module/Core/src/Config/Options/NotFoundRedirectOptions.php @@ -2,19 +2,29 @@ declare(strict_types=1); -namespace Shlinkio\Shlink\Core\Options; +namespace Shlinkio\Shlink\Core\Config\Options; +use Shlinkio\Shlink\Core\Config\EnvVars; use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface; -final class NotFoundRedirectOptions implements NotFoundRedirectConfigInterface +final readonly class NotFoundRedirectOptions implements NotFoundRedirectConfigInterface { public function __construct( - public readonly ?string $invalidShortUrl = null, - public readonly ?string $regular404 = null, - public readonly ?string $baseUrl = null, + public ?string $invalidShortUrl = null, + public ?string $regular404 = null, + public ?string $baseUrl = null, ) { } + public static function fromEnv(): self + { + return new self( + invalidShortUrl: EnvVars::DEFAULT_INVALID_SHORT_URL_REDIRECT->loadFromEnv(), + regular404: EnvVars::DEFAULT_REGULAR_404_REDIRECT->loadFromEnv(), + baseUrl: EnvVars::DEFAULT_BASE_URL_REDIRECT->loadFromEnv(), + ); + } + public function invalidShortUrlRedirect(): ?string { return $this->invalidShortUrl; diff --git a/module/Core/src/Options/QrCodeOptions.php b/module/Core/src/Config/Options/QrCodeOptions.php similarity index 54% rename from module/Core/src/Options/QrCodeOptions.php rename to module/Core/src/Config/Options/QrCodeOptions.php index da130d17..4d85e6cc 100644 --- a/module/Core/src/Options/QrCodeOptions.php +++ b/module/Core/src/Config/Options/QrCodeOptions.php @@ -2,7 +2,9 @@ declare(strict_types=1); -namespace Shlinkio\Shlink\Core\Options; +namespace Shlinkio\Shlink\Core\Config\Options; + +use Shlinkio\Shlink\Core\Config\EnvVars; use const Shlinkio\Shlink\DEFAULT_QR_CODE_BG_COLOR; use const Shlinkio\Shlink\DEFAULT_QR_CODE_COLOR; @@ -13,7 +15,7 @@ use const Shlinkio\Shlink\DEFAULT_QR_CODE_MARGIN; use const Shlinkio\Shlink\DEFAULT_QR_CODE_ROUND_BLOCK_SIZE; use const Shlinkio\Shlink\DEFAULT_QR_CODE_SIZE; -readonly final class QrCodeOptions +final readonly class QrCodeOptions { public function __construct( public int $size = DEFAULT_QR_CODE_SIZE, @@ -27,4 +29,19 @@ readonly final class QrCodeOptions public ?string $logoUrl = null, ) { } + + public static function fromEnv(): self + { + return new self( + size: (int) EnvVars::DEFAULT_QR_CODE_SIZE->loadFromEnv(), + margin: (int) EnvVars::DEFAULT_QR_CODE_MARGIN->loadFromEnv(), + format: EnvVars::DEFAULT_QR_CODE_FORMAT->loadFromEnv(), + errorCorrection: EnvVars::DEFAULT_QR_CODE_ERROR_CORRECTION->loadFromEnv(), + roundBlockSize: (bool) EnvVars::DEFAULT_QR_CODE_ROUND_BLOCK_SIZE->loadFromEnv(), + enabledForDisabledShortUrls: (bool) EnvVars::QR_CODE_FOR_DISABLED_SHORT_URLS->loadFromEnv(), + color: EnvVars::DEFAULT_QR_CODE_COLOR->loadFromEnv(), + bgColor: EnvVars::DEFAULT_QR_CODE_BG_COLOR->loadFromEnv(), + logoUrl: EnvVars::DEFAULT_QR_CODE_LOGO_URL->loadFromEnv(), + ); + } } diff --git a/module/Core/src/Config/Options/RabbitMqOptions.php b/module/Core/src/Config/Options/RabbitMqOptions.php new file mode 100644 index 00000000..4bc86e34 --- /dev/null +++ b/module/Core/src/Config/Options/RabbitMqOptions.php @@ -0,0 +1,19 @@ +loadFromEnv()); + } +} diff --git a/module/Core/src/Options/RedirectOptions.php b/module/Core/src/Config/Options/RedirectOptions.php similarity index 59% rename from module/Core/src/Options/RedirectOptions.php rename to module/Core/src/Config/Options/RedirectOptions.php index dd9f0a6d..75faf097 100644 --- a/module/Core/src/Options/RedirectOptions.php +++ b/module/Core/src/Config/Options/RedirectOptions.php @@ -2,18 +2,19 @@ declare(strict_types=1); -namespace Shlinkio\Shlink\Core\Options; +namespace Shlinkio\Shlink\Core\Config\Options; use Fig\Http\Message\StatusCodeInterface; +use Shlinkio\Shlink\Core\Config\EnvVars; use Shlinkio\Shlink\Core\Util\RedirectStatus; use const Shlinkio\Shlink\DEFAULT_REDIRECT_CACHE_LIFETIME; use const Shlinkio\Shlink\DEFAULT_REDIRECT_STATUS_CODE; -final class RedirectOptions +final readonly class RedirectOptions { - public readonly RedirectStatus $redirectStatusCode; - public readonly int $redirectCacheLifetime; + public RedirectStatus $redirectStatusCode; + public int $redirectCacheLifetime; public function __construct( int $redirectStatusCode = StatusCodeInterface::STATUS_FOUND, @@ -24,4 +25,12 @@ final class RedirectOptions ? $redirectCacheLifetime : DEFAULT_REDIRECT_CACHE_LIFETIME; } + + public static function fromEnv(): self + { + return new self( + redirectStatusCode: (int) EnvVars::REDIRECT_STATUS_CODE->loadFromEnv(), + redirectCacheLifetime: (int) EnvVars::REDIRECT_CACHE_LIFETIME->loadFromEnv(), + ); + } } diff --git a/module/Core/src/Config/Options/RobotsOptions.php b/module/Core/src/Config/Options/RobotsOptions.php new file mode 100644 index 00000000..6a8c364c --- /dev/null +++ b/module/Core/src/Config/Options/RobotsOptions.php @@ -0,0 +1,33 @@ +loadFromEnv(), + userAgents: splitByComma(EnvVars::ROBOTS_USER_AGENTS->loadFromEnv()), + ); + } + + public function hasUserAgents(): bool + { + return count($this->userAgents) > 0; + } +} diff --git a/module/Core/src/Config/Options/TrackingOptions.php b/module/Core/src/Config/Options/TrackingOptions.php new file mode 100644 index 00000000..eddfba34 --- /dev/null +++ b/module/Core/src/Config/Options/TrackingOptions.php @@ -0,0 +1,62 @@ +loadFromEnv(), + trackOrphanVisits: (bool) EnvVars::TRACK_ORPHAN_VISITS->loadFromEnv(), + disableTrackParam: EnvVars::DISABLE_TRACK_PARAM->loadFromEnv(), + disableTracking: (bool) EnvVars::DISABLE_TRACKING->loadFromEnv(), + disableIpTracking: (bool) EnvVars::DISABLE_IP_TRACKING->loadFromEnv(), + disableReferrerTracking: (bool) EnvVars::DISABLE_REFERRER_TRACKING->loadFromEnv(), + disableUaTracking: (bool) EnvVars::DISABLE_UA_TRACKING->loadFromEnv(), + disableTrackingFrom: splitByComma(EnvVars::DISABLE_TRACKING_FROM->loadFromEnv()), + ); + } + + public function hasDisableTrackingFrom(): bool + { + return ! empty($this->disableTrackingFrom); + } + + public function queryHasDisableTrackParam(array $query): bool + { + return $this->disableTrackParam !== null && array_key_exists($this->disableTrackParam, $query); + } +} diff --git a/module/Core/src/Config/Options/UrlShortenerOptions.php b/module/Core/src/Config/Options/UrlShortenerOptions.php new file mode 100644 index 00000000..b815ac0f --- /dev/null +++ b/module/Core/src/Config/Options/UrlShortenerOptions.php @@ -0,0 +1,62 @@ + null, 'hostname' => null], + public int $defaultShortCodesLength = DEFAULT_SHORT_CODES_LENGTH, + public bool $autoResolveTitles = false, + public bool $appendExtraPath = false, + public bool $multiSegmentSlugsEnabled = false, + public bool $trailingSlashEnabled = false, + public ShortUrlMode $mode = ShortUrlMode::STRICT, + ) { + } + + public static function fromEnv(): self + { + $shortCodesLength = max( + (int) EnvVars::DEFAULT_SHORT_CODES_LENGTH->loadFromEnv(), + MIN_SHORT_CODES_LENGTH, + ); + $mode = EnvVars::SHORT_URL_MODE->loadFromEnv(); + + return new self( + domain: [ + 'schema' => ((bool) EnvVars::IS_HTTPS_ENABLED->loadFromEnv()) ? 'https' : 'http', + 'hostname' => EnvVars::DEFAULT_DOMAIN->loadFromEnv(), + ], + defaultShortCodesLength: $shortCodesLength, + autoResolveTitles: (bool) EnvVars::AUTO_RESOLVE_TITLES->loadFromEnv(), + appendExtraPath: (bool) EnvVars::REDIRECT_APPEND_EXTRA_PATH->loadFromEnv(), + multiSegmentSlugsEnabled: (bool) EnvVars::MULTI_SEGMENT_SLUGS_ENABLED->loadFromEnv(), + trailingSlashEnabled: (bool) EnvVars::SHORT_URL_TRAILING_SLASH->loadFromEnv(), + mode: ShortUrlMode::tryFrom($mode) ?? ShortUrlMode::STRICT, + ); + } + + public function isLooseMode(): bool + { + return $this->mode === ShortUrlMode::LOOSE; + } + + public function defaultDomain(): string + { + return $this->domain['hostname'] ?? ''; + } +} diff --git a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php index 4138a72e..4e7360d5 100644 --- a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php +++ b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php @@ -9,15 +9,15 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UriInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use Shlinkio\Shlink\Core\Config; use Shlinkio\Shlink\Core\Config\NotFoundRedirectResolverInterface; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; -use Shlinkio\Shlink\Core\Options; -class NotFoundRedirectHandler implements MiddlewareInterface +readonly class NotFoundRedirectHandler implements MiddlewareInterface { public function __construct( - private Options\NotFoundRedirectOptions $redirectOptions, + private Config\Options\NotFoundRedirectOptions $redirectOptions, private NotFoundRedirectResolverInterface $redirectResolver, private DomainServiceInterface $domainService, ) { diff --git a/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php b/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php index ad4c8070..c348cbbd 100644 --- a/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php +++ b/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\EventDispatcher\Helper; use Shlinkio\Shlink\Common\Mercure\MercureOptions; +use Shlinkio\Shlink\Core\Config\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\EventDispatcher; use Shlinkio\Shlink\Core\Matomo\MatomoOptions; -use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\EventDispatcher\Listener\EnabledListenerCheckerInterface; use Shlinkio\Shlink\IpGeolocation\GeoLite2\GeoLite2Options; diff --git a/module/Core/src/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMq.php b/module/Core/src/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMq.php index daa7cafb..b8c18fb6 100644 --- a/module/Core/src/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMq.php +++ b/module/Core/src/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMq.php @@ -7,10 +7,10 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RabbitMq; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; +use Shlinkio\Shlink\Core\Config\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyNewShortUrlListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; -use Shlinkio\Shlink\Core\Options\RabbitMqOptions; class NotifyNewShortUrlToRabbitMq extends AbstractNotifyNewShortUrlListener { diff --git a/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php b/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php index ddc4221c..bb55f169 100644 --- a/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php +++ b/module/Core/src/EventDispatcher/RabbitMq/NotifyVisitToRabbitMq.php @@ -7,10 +7,10 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RabbitMq; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; +use Shlinkio\Shlink\Core\Config\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyVisitListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; -use Shlinkio\Shlink\Core\Options\RabbitMqOptions; class NotifyVisitToRabbitMq extends AbstractNotifyVisitListener { diff --git a/module/Core/src/Matomo/MatomoOptions.php b/module/Core/src/Matomo/MatomoOptions.php index 23599321..af0ace92 100644 --- a/module/Core/src/Matomo/MatomoOptions.php +++ b/module/Core/src/Matomo/MatomoOptions.php @@ -4,17 +4,31 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Matomo; -class MatomoOptions +use Shlinkio\Shlink\Core\Config\EnvVars; + +final readonly class MatomoOptions { + /** + * @param numeric-string|int|null $siteId + */ public function __construct( - public readonly bool $enabled = false, - public readonly ?string $baseUrl = null, - /** @var numeric-string|int|null */ - private readonly string|int|null $siteId = null, - public readonly ?string $apiToken = null, + public bool $enabled = false, + public ?string $baseUrl = null, + private string|int|null $siteId = null, + public ?string $apiToken = null, ) { } + public static function fromEnv(): self + { + return new self( + enabled: (bool) EnvVars::MATOMO_ENABLED->loadFromEnv(), + baseUrl: EnvVars::MATOMO_BASE_URL->loadFromEnv(), + siteId: EnvVars::MATOMO_SITE_ID->loadFromEnv(), + apiToken: EnvVars::MATOMO_API_TOKEN->loadFromEnv(), + ); + } + public function siteId(): ?int { if ($this->siteId === null) { diff --git a/module/Core/src/Options/DeleteShortUrlsOptions.php b/module/Core/src/Options/DeleteShortUrlsOptions.php deleted file mode 100644 index a645181b..00000000 --- a/module/Core/src/Options/DeleteShortUrlsOptions.php +++ /dev/null @@ -1,16 +0,0 @@ -userAgents) > 0; - } -} diff --git a/module/Core/src/Options/TrackingOptions.php b/module/Core/src/Options/TrackingOptions.php deleted file mode 100644 index d4272374..00000000 --- a/module/Core/src/Options/TrackingOptions.php +++ /dev/null @@ -1,33 +0,0 @@ -disableTrackingFrom); - } - - public function queryHasDisableTrackParam(array $query): bool - { - return $this->disableTrackParam !== null && array_key_exists($this->disableTrackParam, $query); - } -} diff --git a/module/Core/src/Options/UrlShortenerOptions.php b/module/Core/src/Options/UrlShortenerOptions.php deleted file mode 100644 index 03091d75..00000000 --- a/module/Core/src/Options/UrlShortenerOptions.php +++ /dev/null @@ -1,36 +0,0 @@ - null, 'hostname' => null], - public readonly int $defaultShortCodesLength = DEFAULT_SHORT_CODES_LENGTH, - public readonly bool $autoResolveTitles = false, - public readonly bool $appendExtraPath = false, - public readonly bool $multiSegmentSlugsEnabled = false, - public readonly bool $trailingSlashEnabled = false, - public readonly ShortUrlMode $mode = ShortUrlMode::STRICT, - ) { - } - - public function isLooseMode(): bool - { - return $this->mode === ShortUrlMode::LOOSE; - } - - public function defaultDomain(): string - { - return $this->domain['hostname'] ?? ''; - } -} diff --git a/module/Core/src/ShortUrl/DeleteShortUrlService.php b/module/Core/src/ShortUrl/DeleteShortUrlService.php index b65381aa..aeb08c47 100644 --- a/module/Core/src/ShortUrl/DeleteShortUrlService.php +++ b/module/Core/src/ShortUrl/DeleteShortUrlService.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl; use Doctrine\ORM\EntityManagerInterface; +use Shlinkio\Shlink\Core\Config\Options\DeleteShortUrlsOptions; use Shlinkio\Shlink\Core\Exception; -use Shlinkio\Shlink\Core\Options\DeleteShortUrlsOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ExpiredShortUrlsConditions; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; diff --git a/module/Core/src/ShortUrl/Helper/ShortCodeUniquenessHelper.php b/module/Core/src/ShortUrl/Helper/ShortCodeUniquenessHelper.php index b428019e..7f863f6c 100644 --- a/module/Core/src/ShortUrl/Helper/ShortCodeUniquenessHelper.php +++ b/module/Core/src/ShortUrl/Helper/ShortCodeUniquenessHelper.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl\Helper; use Doctrine\ORM\EntityManagerInterface; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository; diff --git a/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php b/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php index 4d801c6f..375d8837 100644 --- a/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php +++ b/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php @@ -8,7 +8,7 @@ use GuzzleHttp\Psr7\Query; use GuzzleHttp\Psr7\Uri; use Laminas\Stdlib\ArrayUtils; use Psr\Http\Message\ServerRequestInterface; -use Shlinkio\Shlink\Core\Options\TrackingOptions; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\Core\RedirectRule\ShortUrlRedirectionResolverInterface; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; diff --git a/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php b/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php index 3f9b6225..0950e042 100644 --- a/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php +++ b/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php @@ -8,7 +8,7 @@ use Fig\Http\Message\RequestMethodInterface; use GuzzleHttp\ClientInterface; use GuzzleHttp\RequestOptions; use Psr\Http\Message\ResponseInterface; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Throwable; use function html_entity_decode; diff --git a/module/Core/src/ShortUrl/Middleware/ExtraPathRedirectMiddleware.php b/module/Core/src/ShortUrl/Middleware/ExtraPathRedirectMiddleware.php index 7780f91b..b164ffd6 100644 --- a/module/Core/src/ShortUrl/Middleware/ExtraPathRedirectMiddleware.php +++ b/module/Core/src/ShortUrl/Middleware/ExtraPathRedirectMiddleware.php @@ -9,9 +9,9 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UriInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlRedirectionBuilderInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface; diff --git a/module/Core/src/ShortUrl/Middleware/TrimTrailingSlashMiddleware.php b/module/Core/src/ShortUrl/Middleware/TrimTrailingSlashMiddleware.php index d3823b27..0b70c3ae 100644 --- a/module/Core/src/ShortUrl/Middleware/TrimTrailingSlashMiddleware.php +++ b/module/Core/src/ShortUrl/Middleware/TrimTrailingSlashMiddleware.php @@ -8,7 +8,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use function rtrim; diff --git a/module/Core/src/ShortUrl/Model/ShortUrlCreation.php b/module/Core/src/ShortUrl/Model/ShortUrlCreation.php index f5336075..c9c85e1b 100644 --- a/module/Core/src/ShortUrl/Model/ShortUrlCreation.php +++ b/module/Core/src/ShortUrl/Model/ShortUrlCreation.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl\Model; use Cake\Chronos\Chronos; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\ValidationException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Helper\TitleResolutionModelInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter; use Shlinkio\Shlink\Rest\Entity\ApiKey; diff --git a/module/Core/src/ShortUrl/Model/Validation/CustomSlugFilter.php b/module/Core/src/ShortUrl/Model/Validation/CustomSlugFilter.php index 2512fc44..ba4e3959 100644 --- a/module/Core/src/ShortUrl/Model/Validation/CustomSlugFilter.php +++ b/module/Core/src/ShortUrl/Model/Validation/CustomSlugFilter.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl\Model\Validation; use Laminas\Filter\FilterInterface; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use function is_string; use function str_replace; diff --git a/module/Core/src/ShortUrl/Model/Validation/CustomSlugValidator.php b/module/Core/src/ShortUrl/Model/Validation/CustomSlugValidator.php index 24afc72e..2bc417b4 100644 --- a/module/Core/src/ShortUrl/Model/Validation/CustomSlugValidator.php +++ b/module/Core/src/ShortUrl/Model/Validation/CustomSlugValidator.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl\Model\Validation; use Laminas\Validator\AbstractValidator; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use function is_string; use function strpbrk; diff --git a/module/Core/src/ShortUrl/Model/Validation/ShortUrlInputFilter.php b/module/Core/src/ShortUrl/Model/Validation/ShortUrlInputFilter.php index f4a35969..3cd7744a 100644 --- a/module/Core/src/ShortUrl/Model/Validation/ShortUrlInputFilter.php +++ b/module/Core/src/ShortUrl/Model/Validation/ShortUrlInputFilter.php @@ -10,7 +10,7 @@ use Laminas\InputFilter\InputFilter; use Laminas\Validator; use Shlinkio\Shlink\Common\Validation\HostAndPortValidator; use Shlinkio\Shlink\Common\Validation\InputFactory; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Rest\Entity\ApiKey; use function is_string; diff --git a/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php b/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php index 3aa6c887..0b79f97d 100644 --- a/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php +++ b/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php @@ -8,8 +8,8 @@ use Doctrine\Common\Collections; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Domain\Entity\Domain; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Tag\Entity\Tag; use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\LockFactory; diff --git a/module/Core/src/ShortUrl/ShortUrlListService.php b/module/Core/src/ShortUrl/ShortUrlListService.php index f8441454..b6539256 100644 --- a/module/Core/src/ShortUrl/ShortUrlListService.php +++ b/module/Core/src/ShortUrl/ShortUrlListService.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl; use Shlinkio\Shlink\Common\Paginator\Paginator; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\ShortUrl\Paginator\Adapter\ShortUrlRepositoryAdapter; use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlListRepositoryInterface; diff --git a/module/Core/src/ShortUrl/ShortUrlResolver.php b/module/Core/src/ShortUrl/ShortUrlResolver.php index 42d274c0..14727ff5 100644 --- a/module/Core/src/ShortUrl/ShortUrlResolver.php +++ b/module/Core/src/ShortUrl/ShortUrlResolver.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl; use Doctrine\ORM\EntityManagerInterface; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository; diff --git a/module/Core/src/Util/RedirectResponseHelper.php b/module/Core/src/Util/RedirectResponseHelper.php index 01e581a7..edb04b8e 100644 --- a/module/Core/src/Util/RedirectResponseHelper.php +++ b/module/Core/src/Util/RedirectResponseHelper.php @@ -6,7 +6,7 @@ namespace Shlinkio\Shlink\Core\Util; use Laminas\Diactoros\Response\RedirectResponse; use Psr\Http\Message\ResponseInterface; -use Shlinkio\Shlink\Core\Options\RedirectOptions; +use Shlinkio\Shlink\Core\Config\Options\RedirectOptions; use function sprintf; diff --git a/module/Core/src/Visit/Model/Visitor.php b/module/Core/src/Visit/Model/Visitor.php index 9cf524bc..ca5d79b2 100644 --- a/module/Core/src/Visit/Model/Visitor.php +++ b/module/Core/src/Visit/Model/Visitor.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Visit\Model; use Psr\Http\Message\ServerRequestInterface; -use Shlinkio\Shlink\Core\Options\TrackingOptions; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use function Shlinkio\Shlink\Core\ipAddressFromRequest; use function Shlinkio\Shlink\Core\isCrawler; diff --git a/module/Core/src/Visit/RequestTracker.php b/module/Core/src/Visit/RequestTracker.php index 824e7c24..986e221c 100644 --- a/module/Core/src/Visit/RequestTracker.php +++ b/module/Core/src/Visit/RequestTracker.php @@ -7,9 +7,9 @@ namespace Shlinkio\Shlink\Core\Visit; use Fig\Http\Message\RequestMethodInterface; use Mezzio\Router\Middleware\ImplicitHeadMiddleware; use Psr\Http\Message\ServerRequestInterface; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; use Shlinkio\Shlink\Core\Exception\InvalidIpFormatException; -use Shlinkio\Shlink\Core\Options\TrackingOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\Util\IpAddressUtils; use Shlinkio\Shlink\Core\Visit\Model\Visitor; diff --git a/module/Core/src/Visit/VisitsTracker.php b/module/Core/src/Visit/VisitsTracker.php index f2e26493..85085220 100644 --- a/module/Core/src/Visit/VisitsTracker.php +++ b/module/Core/src/Visit/VisitsTracker.php @@ -6,8 +6,8 @@ namespace Shlinkio\Shlink\Core\Visit; use Doctrine\ORM; use Psr\EventDispatcher\EventDispatcherInterface; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\Core\EventDispatcher\Event\UrlVisited; -use Shlinkio\Shlink\Core\Options\TrackingOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Model\Visitor; diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index 08564bf9..9afae793 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -16,8 +16,8 @@ use Psr\Http\Server\RequestHandlerInterface; use Psr\Log\NullLogger; use Shlinkio\Shlink\Common\Response\QrCodeResponse; use Shlinkio\Shlink\Core\Action\QrCodeAction; +use Shlinkio\Shlink\Core\Config\Options\QrCodeOptions; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; -use Shlinkio\Shlink\Core\Options\QrCodeOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; diff --git a/module/Core/test/Action/RobotsActionTest.php b/module/Core/test/Action/RobotsActionTest.php index 1d83fb8c..38d80de3 100644 --- a/module/Core/test/Action/RobotsActionTest.php +++ b/module/Core/test/Action/RobotsActionTest.php @@ -10,8 +10,8 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Core\Action\RobotsAction; +use Shlinkio\Shlink\Core\Config\Options\RobotsOptions; use Shlinkio\Shlink\Core\Crawling\CrawlingHelperInterface; -use Shlinkio\Shlink\Core\Options\RobotsOptions; class RobotsActionTest extends TestCase { diff --git a/module/Core/test/Config/NotFoundRedirectResolverTest.php b/module/Core/test/Config/NotFoundRedirectResolverTest.php index 5ef5db2b..75df0948 100644 --- a/module/Core/test/Config/NotFoundRedirectResolverTest.php +++ b/module/Core/test/Config/NotFoundRedirectResolverTest.php @@ -18,8 +18,8 @@ use Psr\Http\Message\UriInterface; use Psr\Log\NullLogger; use Shlinkio\Shlink\Core\Action\RedirectAction; use Shlinkio\Shlink\Core\Config\NotFoundRedirectResolver; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Util\RedirectResponseHelperInterface; use function Laminas\Stratigility\middleware; diff --git a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php index 53642f3a..25d9952f 100644 --- a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php +++ b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php @@ -16,11 +16,11 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UriInterface; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Core\Config\NotFoundRedirectResolverInterface; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; use Shlinkio\Shlink\Core\ErrorHandler\NotFoundRedirectHandler; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; class NotFoundRedirectHandlerTest extends TestCase { diff --git a/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php b/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php index cebde437..180ab48d 100644 --- a/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php +++ b/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Common\Mercure\MercureOptions; +use Shlinkio\Shlink\Core\Config\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\EventDispatcher\Helper\EnabledListenerChecker; use Shlinkio\Shlink\Core\EventDispatcher\Matomo\SendVisitToMatomo; use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyNewShortUrlToMercure; @@ -18,7 +19,6 @@ use Shlinkio\Shlink\Core\EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis; use Shlinkio\Shlink\Core\EventDispatcher\RedisPubSub\NotifyVisitToRedis; use Shlinkio\Shlink\Core\EventDispatcher\UpdateGeoLiteDb; use Shlinkio\Shlink\Core\Matomo\MatomoOptions; -use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\IpGeolocation\GeoLite2\GeoLite2Options; class EnabledListenerCheckerTest extends TestCase diff --git a/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php b/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php index fc44fd87..b0c5a0e0 100644 --- a/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php +++ b/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php @@ -15,11 +15,11 @@ use Psr\Log\LoggerInterface; use RuntimeException; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; use Shlinkio\Shlink\Common\UpdatePublishing\Update; +use Shlinkio\Shlink\Core\Config\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq; use Shlinkio\Shlink\Core\EventDispatcher\Topic; -use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Throwable; diff --git a/module/Core/test/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php b/module/Core/test/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php index 2251d301..ac744824 100644 --- a/module/Core/test/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php +++ b/module/Core/test/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php @@ -16,10 +16,10 @@ use Psr\Log\LoggerInterface; use RuntimeException; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; use Shlinkio\Shlink\Common\UpdatePublishing\Update; +use Shlinkio\Shlink\Core\Config\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\EventDispatcher\RabbitMq\NotifyVisitToRabbitMq; -use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\Visit\Entity\Visit; diff --git a/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php b/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php index 4788818e..faddafeb 100644 --- a/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php +++ b/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php @@ -9,8 +9,8 @@ use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\Options\DeleteShortUrlsOptions; use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException; -use Shlinkio\Shlink\Core\Options\DeleteShortUrlsOptions; use Shlinkio\Shlink\Core\ShortUrl\DeleteShortUrlService; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ExpiredShortUrlsConditions; diff --git a/module/Core/test/ShortUrl/Entity/ShortUrlTest.php b/module/Core/test/ShortUrl/Entity/ShortUrlTest.php index be5b4101..b3720254 100644 --- a/module/Core/test/ShortUrl/Entity/ShortUrlTest.php +++ b/module/Core/test/ShortUrl/Entity/ShortUrlTest.php @@ -9,8 +9,8 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\ShortCodeCannotBeRegeneratedException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode; diff --git a/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php b/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php index efbbde21..de1402f6 100644 --- a/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php @@ -9,8 +9,8 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Domain\Entity\Domain; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortCodeUniquenessHelper; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; diff --git a/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php b/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php index afe83c8d..d1283a78 100644 --- a/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; -use Shlinkio\Shlink\Core\Options\TrackingOptions; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\Core\RedirectRule\ShortUrlRedirectionResolverInterface; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlRedirectionBuilder; diff --git a/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php b/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php index 4e3056b3..b5b8e00c 100644 --- a/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php @@ -16,7 +16,7 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlTitleResolutionHelper; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; diff --git a/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php b/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php index 3965fe18..6815acb6 100644 --- a/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php +++ b/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php @@ -16,9 +16,9 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Core\Action\RedirectAction; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlRedirectionBuilderInterface; use Shlinkio\Shlink\Core\ShortUrl\Middleware\ExtraPathRedirectMiddleware; diff --git a/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php b/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php index b05ab7d9..c37c81a5 100644 --- a/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php +++ b/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Middleware\TrimTrailingSlashMiddleware; class TrimTrailingSlashMiddlewareTest extends TestCase diff --git a/module/Core/test/ShortUrl/Model/ShortUrlCreationTest.php b/module/Core/test/ShortUrl/Model/ShortUrlCreationTest.php index b84b5b27..e963923b 100644 --- a/module/Core/test/ShortUrl/Model/ShortUrlCreationTest.php +++ b/module/Core/test/ShortUrl/Model/ShortUrlCreationTest.php @@ -8,8 +8,8 @@ use Cake\Chronos\Chronos; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\ValidationException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode; use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter; diff --git a/module/Core/test/ShortUrl/Model/Validation/CustomSlugValidatorTest.php b/module/Core/test/ShortUrl/Model/Validation/CustomSlugValidatorTest.php index 290fe63d..86f695c7 100644 --- a/module/Core/test/ShortUrl/Model/Validation/CustomSlugValidatorTest.php +++ b/module/Core/test/ShortUrl/Model/Validation/CustomSlugValidatorTest.php @@ -7,7 +7,7 @@ namespace ShlinkioTest\Shlink\Core\ShortUrl\Model\Validation; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\CustomSlugValidator; use stdClass; diff --git a/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php b/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php index 43860909..d6223734 100644 --- a/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php +++ b/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php @@ -10,9 +10,9 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Resolver\PersistenceShortUrlRelationResolver; use Shlinkio\Shlink\Core\Tag\Entity\Tag; use Shlinkio\Shlink\Core\Tag\Repository\TagRepository; diff --git a/module/Core/test/ShortUrl/ShortUrlListServiceTest.php b/module/Core/test/ShortUrl/ShortUrlListServiceTest.php index a469ed60..d8663761 100644 --- a/module/Core/test/ShortUrl/ShortUrlListServiceTest.php +++ b/module/Core/test/ShortUrl/ShortUrlListServiceTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlListRepositoryInterface; diff --git a/module/Core/test/ShortUrl/ShortUrlResolverTest.php b/module/Core/test/ShortUrl/ShortUrlResolverTest.php index 1b3aa564..e8443a13 100644 --- a/module/Core/test/ShortUrl/ShortUrlResolverTest.php +++ b/module/Core/test/ShortUrl/ShortUrlResolverTest.php @@ -12,8 +12,8 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; diff --git a/module/Core/test/Util/RedirectResponseHelperTest.php b/module/Core/test/Util/RedirectResponseHelperTest.php index 63e55e2e..89d3fa5a 100644 --- a/module/Core/test/Util/RedirectResponseHelperTest.php +++ b/module/Core/test/Util/RedirectResponseHelperTest.php @@ -8,7 +8,7 @@ use Laminas\Diactoros\Response\RedirectResponse; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Core\Options\RedirectOptions; +use Shlinkio\Shlink\Core\Config\Options\RedirectOptions; use Shlinkio\Shlink\Core\Util\RedirectResponseHelper; class RedirectResponseHelperTest extends TestCase diff --git a/module/Core/test/Visit/Model/VisitorTest.php b/module/Core/test/Visit/Model/VisitorTest.php index 74065d7d..04e57179 100644 --- a/module/Core/test/Visit/Model/VisitorTest.php +++ b/module/Core/test/Visit/Model/VisitorTest.php @@ -7,7 +7,7 @@ namespace ShlinkioTest\Shlink\Core\Visit\Model; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Core\Options\TrackingOptions; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\Core\Visit\Model\Visitor; use function random_int; diff --git a/module/Core/test/Visit/RequestTrackerTest.php b/module/Core/test/Visit/RequestTrackerTest.php index c8746f91..ae0a74c4 100644 --- a/module/Core/test/Visit/RequestTrackerTest.php +++ b/module/Core/test/Visit/RequestTrackerTest.php @@ -13,8 +13,8 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; use Shlinkio\Shlink\Common\Middleware\IpAddressMiddlewareFactory; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; -use Shlinkio\Shlink\Core\Options\TrackingOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\Visit\Model\Visitor; use Shlinkio\Shlink\Core\Visit\RequestTracker; diff --git a/module/Core/test/Visit/VisitsTrackerTest.php b/module/Core/test/Visit/VisitsTrackerTest.php index d6cbf4bf..414f5254 100644 --- a/module/Core/test/Visit/VisitsTrackerTest.php +++ b/module/Core/test/Visit/VisitsTrackerTest.php @@ -10,8 +10,8 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; +use Shlinkio\Shlink\Core\Config\Options\TrackingOptions; use Shlinkio\Shlink\Core\EventDispatcher\Event\UrlVisited; -use Shlinkio\Shlink\Core\Options\TrackingOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Model\Visitor; diff --git a/module/Rest/config/dependencies.config.php b/module/Rest/config/dependencies.config.php index d334d5b0..3d7a66a4 100644 --- a/module/Rest/config/dependencies.config.php +++ b/module/Rest/config/dependencies.config.php @@ -10,8 +10,8 @@ use Mezzio\ProblemDetails\ProblemDetailsResponseFactory; use Mezzio\Router\Middleware\ImplicitOptionsMiddleware; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\Mercure\LcobucciJwtProvider; +use Shlinkio\Shlink\Core\Config; use Shlinkio\Shlink\Core\Domain\DomainService; -use Shlinkio\Shlink\Core\Options; use Shlinkio\Shlink\Core\RedirectRule; use Shlinkio\Shlink\Core\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformer; @@ -64,17 +64,17 @@ return [ ConfigAbstractFactory::class => [ ApiKeyService::class => ['em'], - Action\HealthAction::class => ['em', Options\AppOptions::class], + Action\HealthAction::class => ['em', Config\Options\AppOptions::class], Action\MercureInfoAction::class => [LcobucciJwtProvider::class, 'config.mercure'], Action\ShortUrl\CreateShortUrlAction::class => [ ShortUrl\UrlShortener::class, ShortUrlDataTransformer::class, - Options\UrlShortenerOptions::class, + Config\Options\UrlShortenerOptions::class, ], Action\ShortUrl\SingleStepCreateShortUrlAction::class => [ ShortUrl\UrlShortener::class, ShortUrlDataTransformer::class, - Options\UrlShortenerOptions::class, + Config\Options\UrlShortenerOptions::class, ], Action\ShortUrl\EditShortUrlAction::class => [ShortUrl\ShortUrlService::class, ShortUrlDataTransformer::class], Action\ShortUrl\DeleteShortUrlAction::class => [ShortUrl\DeleteShortUrlService::class], @@ -101,7 +101,7 @@ return [ Action\Tag\TagsStatsAction::class => [TagService::class], Action\Tag\DeleteTagsAction::class => [TagService::class], Action\Tag\UpdateTagAction::class => [TagService::class], - Action\Domain\ListDomainsAction::class => [DomainService::class, Options\NotFoundRedirectOptions::class], + Action\Domain\ListDomainsAction::class => [DomainService::class, Config\Options\NotFoundRedirectOptions::class], Action\Domain\DomainRedirectsAction::class => [DomainService::class], Action\RedirectRule\ListRedirectRulesAction::class => [ ShortUrl\ShortUrlResolver::class, diff --git a/module/Rest/src/Action/Domain/ListDomainsAction.php b/module/Rest/src/Action/Domain/ListDomainsAction.php index e50ada16..d156a720 100644 --- a/module/Rest/src/Action/Domain/ListDomainsAction.php +++ b/module/Rest/src/Action/Domain/ListDomainsAction.php @@ -8,8 +8,8 @@ use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Shlinkio\Shlink\Core\Config\NotFoundRedirects; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; diff --git a/module/Rest/src/Action/HealthAction.php b/module/Rest/src/Action/HealthAction.php index 809bf4d1..ce731330 100644 --- a/module/Rest/src/Action/HealthAction.php +++ b/module/Rest/src/Action/HealthAction.php @@ -8,7 +8,7 @@ use Doctrine\ORM\EntityManagerInterface; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Shlinkio\Shlink\Core\Options\AppOptions; +use Shlinkio\Shlink\Core\Config\Options\AppOptions; use Throwable; class HealthAction extends AbstractRestAction diff --git a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index 65f47d95..75d5480b 100644 --- a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -7,8 +7,8 @@ namespace Shlinkio\Shlink\Rest\Action\ShortUrl; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\ValidationException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformerInterface; use Shlinkio\Shlink\Core\ShortUrl\UrlShortenerInterface; diff --git a/module/Rest/test/Action/Domain/ListDomainsActionTest.php b/module/Rest/test/Action/Domain/ListDomainsActionTest.php index 41906539..4864048c 100644 --- a/module/Rest/test/Action/Domain/ListDomainsActionTest.php +++ b/module/Rest/test/Action/Domain/ListDomainsActionTest.php @@ -10,10 +10,10 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Core\Config\NotFoundRedirects; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Model\DomainItem; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Rest\Action\Domain\ListDomainsAction; use Shlinkio\Shlink\Rest\Entity\ApiKey; diff --git a/module/Rest/test/Action/Domain/Request/DomainRedirectsRequestTest.php b/module/Rest/test/Action/Domain/Request/DomainRedirectsRequestTest.php index 89b93b80..292c1748 100644 --- a/module/Rest/test/Action/Domain/Request/DomainRedirectsRequestTest.php +++ b/module/Rest/test/Action/Domain/Request/DomainRedirectsRequestTest.php @@ -8,8 +8,8 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface; +use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Exception\ValidationException; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Rest\Action\Domain\Request\DomainRedirectsRequest; class DomainRedirectsRequestTest extends TestCase diff --git a/module/Rest/test/Action/HealthActionTest.php b/module/Rest/test/Action/HealthActionTest.php index 59075646..aae90f49 100644 --- a/module/Rest/test/Action/HealthActionTest.php +++ b/module/Rest/test/Action/HealthActionTest.php @@ -14,7 +14,7 @@ use Laminas\Diactoros\ServerRequest; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Core\Options\AppOptions; +use Shlinkio\Shlink\Core\Config\Options\AppOptions; use Shlinkio\Shlink\Rest\Action\HealthAction; class HealthActionTest extends TestCase diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index 7361df5c..06cd5554 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -12,8 +12,8 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\ValidationException; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\UrlShorteningResult; diff --git a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index 69914f0e..d28c3b49 100644 --- a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php @@ -8,7 +8,7 @@ use Laminas\Diactoros\ServerRequest; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; +use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\UrlShorteningResult; diff --git a/shlink-dev.env b/shlink-dev.env new file mode 100644 index 00000000..02c2aa92 --- /dev/null +++ b/shlink-dev.env @@ -0,0 +1,65 @@ +LC_ALL=C +#APP_ENV=dev + +# URL shortener +IS_HTTPS_ENABLED=false + +# Database - MySQL +DB_DRIVER=mysql +DB_USER=root +DB_PASSWORD=root +DB_NAME=shlink +# DB_NAME=shlink_foo +DB_HOST=shlink_db_mysql + +# Database - Maria +#DB_DRIVER=maria +#DB_USER=root +#DB_PASSWORD=root +#DB_NAME=shlink_foo +#DB_HOST=shlink_db_maria + +# Database - Postgres +#DB_DRIVER=postgres +#DB_USER=postgres +#DB_PASSWORD=root +#DB_NAME=shlink_foo +#DB_HOST=shlink_db_postgres + +# Database - MSSQL +#DB_DRIVER=mssql +#DB_USER=sa +#DB_PASSWORD=Passw0rd! +#DB_NAME=shlink_foo +#DB_HOST=shlink_db_ms + +# Matomo +# Dev matomo instance needs to be manually configured once before enabling the configuration below: +# 1. Go to http://localhost:8003 and follow the installation instructions. +# 2. Open data/infra/matomo/config/config.ini.php and replace `trusted_hosts[] = "localhost"` with +# `trusted_hosts[] = "localhost:8003"` (see https://github.com/matomo-org/matomo/issues/9549) +# 3. Go to http://localhost:8003/index.php?module=SitesManager&action=index and paste the ID for the site you just +# created into the `MATOMO_SITE_ID` var below. +# 4. Go to http://localhost:8003/index.php?module=UsersManager&action=userSecurity, scroll down, click +# "Create new token" and once generated, paste the token into the `MATOMO_API_TOKEN` var below. +# 5. Copy the config below and paste it in a new shlink-dev.local.env file. +#MATOMO_ENABLED=false +#MATOMO_BASE_URL=http://shlink_matomo +#MATOMO_SITE_ID= +#MATOMO_API_TOKEN= + +# Mercure +MERCURE_PUBLIC_HUB_URL=http://localhost:8002 +MERCURE_INTERNAL_HUB_URL=http://shlink_mercure_proxy +MERCURE_JWT_SECRET=mercure_jwt_key_long_enough_to_avoid_error + +# RabbitMQ +RABBITMQ_ENABLED=true +RABBITMQ_HOST=shlink_rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_USER=rabbit +RABBITMQ_PASSWORD=rabbit + +# Redis +REDIS_PUB_SUB_ENABLED=true +REDIS_SERVERS=tcp://shlink_redis:6379