From 5beaab85ac56e0b9c553655d6d0d1259de4362a4 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 May 2020 11:17:07 +0200 Subject: [PATCH 1/6] Renamed GetVisitsAction to ShortUrlVisitsAction --- module/Rest/config/dependencies.config.php | 4 ++-- module/Rest/config/routes.config.php | 2 +- .../{GetVisitsAction.php => ShortUrlVisitsAction.php} | 2 +- ...tVisitsActionTest.php => ShortUrlVisitsActionTest.php} | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) rename module/Rest/src/Action/Visit/{GetVisitsAction.php => ShortUrlVisitsAction.php} (96%) rename module/Rest/test/Action/Visit/{GetVisitsActionTest.php => ShortUrlVisitsActionTest.php} (89%) diff --git a/module/Rest/config/dependencies.config.php b/module/Rest/config/dependencies.config.php index f6af6f85..1daa9300 100644 --- a/module/Rest/config/dependencies.config.php +++ b/module/Rest/config/dependencies.config.php @@ -28,7 +28,7 @@ return [ Action\ShortUrl\ResolveShortUrlAction::class => ConfigAbstractFactory::class, Action\ShortUrl\ListShortUrlsAction::class => ConfigAbstractFactory::class, Action\ShortUrl\EditShortUrlTagsAction::class => ConfigAbstractFactory::class, - Action\Visit\GetVisitsAction::class => ConfigAbstractFactory::class, + Action\Visit\ShortUrlVisitsAction::class => ConfigAbstractFactory::class, Action\Tag\ListTagsAction::class => ConfigAbstractFactory::class, Action\Tag\DeleteTagsAction::class => ConfigAbstractFactory::class, Action\Tag\CreateTagsAction::class => ConfigAbstractFactory::class, @@ -65,7 +65,7 @@ return [ Service\ShortUrl\ShortUrlResolver::class, 'config.url_shortener.domain', ], - Action\Visit\GetVisitsAction::class => [Service\VisitsTracker::class, 'Logger_Shlink'], + Action\Visit\ShortUrlVisitsAction::class => [Service\VisitsTracker::class, 'Logger_Shlink'], Action\ShortUrl\ListShortUrlsAction::class => [ Service\ShortUrlService::class, 'config.url_shortener.domain', diff --git a/module/Rest/config/routes.config.php b/module/Rest/config/routes.config.php index 3ced8357..7498d1b3 100644 --- a/module/Rest/config/routes.config.php +++ b/module/Rest/config/routes.config.php @@ -26,7 +26,7 @@ return [ Action\ShortUrl\EditShortUrlTagsAction::getRouteDef([$dropDomainMiddleware]), // Visits - Action\Visit\GetVisitsAction::getRouteDef([$dropDomainMiddleware]), + Action\Visit\ShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]), // Tags Action\Tag\ListTagsAction::getRouteDef(), diff --git a/module/Rest/src/Action/Visit/GetVisitsAction.php b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php similarity index 96% rename from module/Rest/src/Action/Visit/GetVisitsAction.php rename to module/Rest/src/Action/Visit/ShortUrlVisitsAction.php index bd6ae5a5..f7f0224a 100644 --- a/module/Rest/src/Action/Visit/GetVisitsAction.php +++ b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; -class GetVisitsAction extends AbstractRestAction +class ShortUrlVisitsAction extends AbstractRestAction { use PaginatorUtilsTrait; diff --git a/module/Rest/test/Action/Visit/GetVisitsActionTest.php b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php similarity index 89% rename from module/Rest/test/Action/Visit/GetVisitsActionTest.php rename to module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php index a1f1681a..07508acf 100644 --- a/module/Rest/test/Action/Visit/GetVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php @@ -15,17 +15,17 @@ use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Service\VisitsTracker; -use Shlinkio\Shlink\Rest\Action\Visit\GetVisitsAction; +use Shlinkio\Shlink\Rest\Action\Visit\ShortUrlVisitsAction; -class GetVisitsActionTest extends TestCase +class ShortUrlVisitsActionTest extends TestCase { - private GetVisitsAction $action; + private ShortUrlVisitsAction $action; private ObjectProphecy $visitsTracker; public function setUp(): void { $this->visitsTracker = $this->prophesize(VisitsTracker::class); - $this->action = new GetVisitsAction($this->visitsTracker->reveal()); + $this->action = new ShortUrlVisitsAction($this->visitsTracker->reveal()); } /** @test */ From 1ef10f11cb4a33acd50f51b94e8e9ee532ce2166 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 May 2020 11:40:02 +0200 Subject: [PATCH 2/6] Created new action to get default visit stats --- module/Core/config/dependencies.config.php | 2 ++ module/Core/src/Visit/Model/VisitsStats.php | 24 ++++++++++++++ module/Core/src/Visit/VisitsStatsHelper.php | 32 ++++++++++++++++++ .../src/Visit/VisitsStatsHelperInterface.php | 12 +++++++ module/Rest/config/dependencies.config.php | 3 ++ module/Rest/config/routes.config.php | 1 + .../src/Action/Visit/GlobalVisitsAction.php | 33 +++++++++++++++++++ .../Action/GlobalVisitsActionTest.php | 21 ++++++++++++ ...nTest.php => ShortUrlVisitsActionTest.php} | 2 +- 9 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 module/Core/src/Visit/Model/VisitsStats.php create mode 100644 module/Core/src/Visit/VisitsStatsHelper.php create mode 100644 module/Core/src/Visit/VisitsStatsHelperInterface.php create mode 100644 module/Rest/src/Action/Visit/GlobalVisitsAction.php create mode 100644 module/Rest/test-api/Action/GlobalVisitsActionTest.php rename module/Rest/test-api/Action/{GetVisitsActionTest.php => ShortUrlVisitsActionTest.php} (97%) diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index 63e6cfed..67d18c40 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -27,6 +27,7 @@ return [ Service\VisitsTracker::class => ConfigAbstractFactory::class, Service\ShortUrlService::class => ConfigAbstractFactory::class, Visit\VisitLocator::class => ConfigAbstractFactory::class, + Visit\VisitsStatsHelper::class => ConfigAbstractFactory::class, Service\Tag\TagService::class => ConfigAbstractFactory::class, Service\ShortUrl\DeleteShortUrlService::class => ConfigAbstractFactory::class, Service\ShortUrl\ShortUrlResolver::class => ConfigAbstractFactory::class, @@ -56,6 +57,7 @@ return [ Service\VisitsTracker::class => ['em', EventDispatcherInterface::class], Service\ShortUrlService::class => ['em', Service\ShortUrl\ShortUrlResolver::class, Util\UrlValidator::class], Visit\VisitLocator::class => ['em'], + Visit\VisitsStatsHelper::class => ['em'], Service\Tag\TagService::class => ['em'], Service\ShortUrl\DeleteShortUrlService::class => [ 'em', diff --git a/module/Core/src/Visit/Model/VisitsStats.php b/module/Core/src/Visit/Model/VisitsStats.php new file mode 100644 index 00000000..ac5083c7 --- /dev/null +++ b/module/Core/src/Visit/Model/VisitsStats.php @@ -0,0 +1,24 @@ +visitsCount = $visitsCount; + } + + public function jsonSerialize(): array + { + return [ + 'visitsCount' => $this->visitsCount, + ]; + } +} diff --git a/module/Core/src/Visit/VisitsStatsHelper.php b/module/Core/src/Visit/VisitsStatsHelper.php new file mode 100644 index 00000000..de3219ff --- /dev/null +++ b/module/Core/src/Visit/VisitsStatsHelper.php @@ -0,0 +1,32 @@ +em = $em; + } + + public function getVisitsStats(): VisitsStats + { + return new VisitsStats($this->getVisitsCount()); + } + + private function getVisitsCount(): int + { + /** @var VisitRepository $visitsRepo */ + $visitsRepo = $this->em->getRepository(Visit::class); + return $visitsRepo->count([]); + } +} diff --git a/module/Core/src/Visit/VisitsStatsHelperInterface.php b/module/Core/src/Visit/VisitsStatsHelperInterface.php new file mode 100644 index 00000000..81423cb0 --- /dev/null +++ b/module/Core/src/Visit/VisitsStatsHelperInterface.php @@ -0,0 +1,12 @@ + ConfigAbstractFactory::class, Action\ShortUrl\EditShortUrlTagsAction::class => ConfigAbstractFactory::class, Action\Visit\ShortUrlVisitsAction::class => ConfigAbstractFactory::class, + Action\Visit\GlobalVisitsAction::class => ConfigAbstractFactory::class, Action\Tag\ListTagsAction::class => ConfigAbstractFactory::class, Action\Tag\DeleteTagsAction::class => ConfigAbstractFactory::class, Action\Tag\CreateTagsAction::class => ConfigAbstractFactory::class, @@ -66,6 +68,7 @@ return [ 'config.url_shortener.domain', ], Action\Visit\ShortUrlVisitsAction::class => [Service\VisitsTracker::class, 'Logger_Shlink'], + Action\Visit\GlobalVisitsAction::class => [Visit\VisitsStatsHelper::class, 'Logger_Shlink'], Action\ShortUrl\ListShortUrlsAction::class => [ Service\ShortUrlService::class, 'config.url_shortener.domain', diff --git a/module/Rest/config/routes.config.php b/module/Rest/config/routes.config.php index 7498d1b3..d2795971 100644 --- a/module/Rest/config/routes.config.php +++ b/module/Rest/config/routes.config.php @@ -27,6 +27,7 @@ return [ // Visits Action\Visit\ShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]), + Action\Visit\GlobalVisitsAction::getRouteDef(), // Tags Action\Tag\ListTagsAction::getRouteDef(), diff --git a/module/Rest/src/Action/Visit/GlobalVisitsAction.php b/module/Rest/src/Action/Visit/GlobalVisitsAction.php new file mode 100644 index 00000000..1946e222 --- /dev/null +++ b/module/Rest/src/Action/Visit/GlobalVisitsAction.php @@ -0,0 +1,33 @@ +statsHelper = $statsHelper; + } + + public function handle(ServerRequestInterface $request): ResponseInterface + { + return new JsonResponse([ + 'visits' => $this->statsHelper->getVisitsStats(), + ]); + } +} diff --git a/module/Rest/test-api/Action/GlobalVisitsActionTest.php b/module/Rest/test-api/Action/GlobalVisitsActionTest.php new file mode 100644 index 00000000..8e4f5e11 --- /dev/null +++ b/module/Rest/test-api/Action/GlobalVisitsActionTest.php @@ -0,0 +1,21 @@ +callApiWithKey(self::METHOD_GET, '/visits'); + $payload = $this->getJsonResponsePayload($resp); + + $this->assertArrayHasKey('visits', $payload); + $this->assertArrayHasKey('visitsCount', $payload['visits']); + $this->assertEquals(7, $payload['visits']['visitsCount']); + } +} diff --git a/module/Rest/test-api/Action/GetVisitsActionTest.php b/module/Rest/test-api/Action/ShortUrlVisitsActionTest.php similarity index 97% rename from module/Rest/test-api/Action/GetVisitsActionTest.php rename to module/Rest/test-api/Action/ShortUrlVisitsActionTest.php index cee466a3..ea39a267 100644 --- a/module/Rest/test-api/Action/GetVisitsActionTest.php +++ b/module/Rest/test-api/Action/ShortUrlVisitsActionTest.php @@ -11,7 +11,7 @@ use ShlinkioApiTest\Shlink\Rest\Utils\NotFoundUrlHelpersTrait; use function GuzzleHttp\Psr7\build_query; use function sprintf; -class GetVisitsActionTest extends ApiTestCase +class ShortUrlVisitsActionTest extends ApiTestCase { use NotFoundUrlHelpersTrait; From 3232ab401f3703b7a6323249f76ef4f1216ddd66 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 May 2020 11:44:55 +0200 Subject: [PATCH 3/6] Documented new visits endpoint --- docs/swagger/definitions/VisitStats.json | 10 +++++ docs/swagger/paths/v2_visits.json | 54 ++++++++++++++++++++++++ docs/swagger/swagger.json | 3 ++ 3 files changed, 67 insertions(+) create mode 100644 docs/swagger/definitions/VisitStats.json create mode 100644 docs/swagger/paths/v2_visits.json diff --git a/docs/swagger/definitions/VisitStats.json b/docs/swagger/definitions/VisitStats.json new file mode 100644 index 00000000..5f439c9b --- /dev/null +++ b/docs/swagger/definitions/VisitStats.json @@ -0,0 +1,10 @@ +{ + "type": "object", + "required": ["visitsCount"], + "properties": { + "visitsCount": { + "type": "number", + "description": "The total amount of visits received." + } + } +} diff --git a/docs/swagger/paths/v2_visits.json b/docs/swagger/paths/v2_visits.json new file mode 100644 index 00000000..089223b3 --- /dev/null +++ b/docs/swagger/paths/v2_visits.json @@ -0,0 +1,54 @@ +{ + "get": { + "operationId": "getGlobalVisits", + "tags": [ + "Visits" + ], + "summary": "Get general visits stats", + "description": "Get general visits stats not linked to one specific short URL.", + "parameters": [ + { + "$ref": "../parameters/version.json" + } + ], + "security": [ + { + "ApiKey": [] + } + ], + "responses": { + "200": { + "description": "Visits stats.", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "visits": { + "$ref": "../definitions/VisitStats.json" + } + } + } + } + }, + "examples": { + "application/json": { + "visits": { + "visitsCount": 1569874 + } + } + } + }, + "500": { + "description": "Unexpected error.", + "content": { + "application/problem+json": { + "schema": { + "$ref": "../definitions/Error.json" + } + } + } + } + } + } +} diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index c30bab97..e7663820 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -78,6 +78,9 @@ "$ref": "paths/v1_tags.json" }, + "/rest/v{version}/visits": { + "$ref": "paths/v2_visits.json" + }, "/rest/v{version}/short-urls/{shortCode}/visits": { "$ref": "paths/v1_short-urls_{shortCode}_visits.json" }, From b5947d1642f0aa32cf4ba6241a7e7deb244e7115 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 May 2020 11:57:46 +0200 Subject: [PATCH 4/6] Created more unit tests --- .../Core/test/Visit/VisitsStatsHelperTest.php | 50 +++++++++++++++++++ module/Rest/src/Action/AbstractRestAction.php | 2 +- .../Action/Visit/GlobalVisitsActionTest.php | 39 +++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 module/Core/test/Visit/VisitsStatsHelperTest.php create mode 100644 module/Rest/test/Action/Visit/GlobalVisitsActionTest.php diff --git a/module/Core/test/Visit/VisitsStatsHelperTest.php b/module/Core/test/Visit/VisitsStatsHelperTest.php new file mode 100644 index 00000000..a4b692d5 --- /dev/null +++ b/module/Core/test/Visit/VisitsStatsHelperTest.php @@ -0,0 +1,50 @@ +em = $this->prophesize(EntityManagerInterface::class); + $this->helper = new VisitsStatsHelper($this->em->reveal()); + } + + /** + * @test + * @dataProvider provideCounts + */ + public function returnsExpectedVisitsStats(int $expectedCount): void + { + $repo = $this->prophesize(VisitRepository::class); + $count = $repo->count([])->willReturn($expectedCount); + $getRepo = $this->em->getRepository(Visit::class)->willReturn($repo->reveal()); + + $stats = $this->helper->getVisitsStats(); + + $this->assertEquals(new VisitsStats($expectedCount), $stats); + $count->shouldHaveBeenCalledOnce(); + $getRepo->shouldHaveBeenCalledOnce(); + } + + public function provideCounts(): iterable + { + return map(range(0, 50, 5), fn (int $value) => [$value]); + } +} diff --git a/module/Rest/src/Action/AbstractRestAction.php b/module/Rest/src/Action/AbstractRestAction.php index 826290b7..589e2d0e 100644 --- a/module/Rest/src/Action/AbstractRestAction.php +++ b/module/Rest/src/Action/AbstractRestAction.php @@ -21,7 +21,7 @@ abstract class AbstractRestAction implements RequestHandlerInterface, RequestMet public function __construct(?LoggerInterface $logger = null) { - $this->logger = $logger ?: new NullLogger(); + $this->logger = $logger ?? new NullLogger(); } public static function getRouteDef(array $prevMiddleware = [], array $postMiddleware = []): array diff --git a/module/Rest/test/Action/Visit/GlobalVisitsActionTest.php b/module/Rest/test/Action/Visit/GlobalVisitsActionTest.php new file mode 100644 index 00000000..7e1dec06 --- /dev/null +++ b/module/Rest/test/Action/Visit/GlobalVisitsActionTest.php @@ -0,0 +1,39 @@ +helper = $this->prophesize(VisitsStatsHelperInterface::class); + $this->action = new GlobalVisitsAction($this->helper->reveal()); + } + + /** @test */ + public function statsAreReturnedFromHelper(): void + { + $stats = new VisitsStats(5); + $getStats = $this->helper->getVisitsStats()->willReturn($stats); + + /** @var JsonResponse $resp */ + $resp = $this->action->handle(ServerRequestFactory::fromGlobals()); + $payload = $resp->getPayload(); + + $this->assertEquals($payload, ['visits' => $stats]); + $getStats->shouldHaveBeenCalledOnce(); + } +} From d067f52ac2eaedd6ace9925757d195913c378113 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 May 2020 11:58:59 +0200 Subject: [PATCH 5/6] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 584b8dc8..0ed6d0eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this Also, Shlink exposes a new endpoint `GET /rest/v2/mercure-info`, which returns the public URL of the mercure hub, and a valid JWT that can be used to subsribe to updates. +* [#673](https://github.com/shlinkio/shlink/issues/673) Added new `[GET /visits]` rest endpoint which returns basic visits stats. + #### Changed * *Nothing* From aece9e68ba9ca6ad8d4c5b3623f0fa4129e3e848 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 1 May 2020 12:08:44 +0200 Subject: [PATCH 6/6] Removed logger dependency from rest actions --- module/Rest/config/dependencies.config.php | 36 +++++++------------ module/Rest/src/Action/AbstractRestAction.php | 9 ----- module/Rest/src/Action/HealthAction.php | 4 +-- module/Rest/src/Action/MercureInfoAction.php | 9 ++--- .../ShortUrl/AbstractCreateShortUrlAction.php | 9 ++--- .../Action/ShortUrl/DeleteShortUrlAction.php | 4 +-- .../Action/ShortUrl/EditShortUrlAction.php | 4 +-- .../ShortUrl/EditShortUrlTagsAction.php | 4 +-- .../Action/ShortUrl/ListShortUrlsAction.php | 9 ++--- .../Action/ShortUrl/ResolveShortUrlAction.php | 9 ++--- .../SingleStepCreateShortUrlAction.php | 6 ++-- .../Rest/src/Action/Tag/CreateTagsAction.php | 4 +-- .../Rest/src/Action/Tag/DeleteTagsAction.php | 4 +-- module/Rest/src/Action/Tag/ListTagsAction.php | 4 +-- .../Rest/src/Action/Tag/UpdateTagAction.php | 4 +-- .../src/Action/Visit/GlobalVisitsAction.php | 4 +-- .../src/Action/Visit/ShortUrlVisitsAction.php | 4 +-- 17 files changed, 33 insertions(+), 94 deletions(-) diff --git a/module/Rest/config/dependencies.config.php b/module/Rest/config/dependencies.config.php index d067d739..bd347897 100644 --- a/module/Rest/config/dependencies.config.php +++ b/module/Rest/config/dependencies.config.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Laminas\ServiceManager\Factory\InvokableFactory; use Mezzio\Router\Middleware\ImplicitOptionsMiddleware; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\Mercure\LcobucciJwtProvider; use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Service; @@ -48,37 +47,28 @@ return [ ConfigAbstractFactory::class => [ ApiKeyService::class => ['em'], - Action\HealthAction::class => ['em', AppOptions::class, 'Logger_Shlink'], - Action\MercureInfoAction::class => [LcobucciJwtProvider::class, 'config.mercure', 'Logger_Shlink'], - Action\ShortUrl\CreateShortUrlAction::class => [ - Service\UrlShortener::class, - 'config.url_shortener.domain', - 'Logger_Shlink', - ], + Action\HealthAction::class => ['em', AppOptions::class], + Action\MercureInfoAction::class => [LcobucciJwtProvider::class, 'config.mercure'], + Action\ShortUrl\CreateShortUrlAction::class => [Service\UrlShortener::class, 'config.url_shortener.domain'], Action\ShortUrl\SingleStepCreateShortUrlAction::class => [ Service\UrlShortener::class, ApiKeyService::class, 'config.url_shortener.domain', - 'Logger_Shlink', ], - Action\ShortUrl\EditShortUrlAction::class => [Service\ShortUrlService::class, 'Logger_Shlink'], - Action\ShortUrl\DeleteShortUrlAction::class => [Service\ShortUrl\DeleteShortUrlService::class, 'Logger_Shlink'], + Action\ShortUrl\EditShortUrlAction::class => [Service\ShortUrlService::class], + Action\ShortUrl\DeleteShortUrlAction::class => [Service\ShortUrl\DeleteShortUrlService::class], Action\ShortUrl\ResolveShortUrlAction::class => [ Service\ShortUrl\ShortUrlResolver::class, 'config.url_shortener.domain', ], - Action\Visit\ShortUrlVisitsAction::class => [Service\VisitsTracker::class, 'Logger_Shlink'], - Action\Visit\GlobalVisitsAction::class => [Visit\VisitsStatsHelper::class, 'Logger_Shlink'], - Action\ShortUrl\ListShortUrlsAction::class => [ - Service\ShortUrlService::class, - 'config.url_shortener.domain', - 'Logger_Shlink', - ], - Action\ShortUrl\EditShortUrlTagsAction::class => [Service\ShortUrlService::class, 'Logger_Shlink'], - Action\Tag\ListTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], - Action\Tag\DeleteTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], - Action\Tag\CreateTagsAction::class => [Service\Tag\TagService::class, LoggerInterface::class], - Action\Tag\UpdateTagAction::class => [Service\Tag\TagService::class, LoggerInterface::class], + Action\Visit\ShortUrlVisitsAction::class => [Service\VisitsTracker::class], + Action\Visit\GlobalVisitsAction::class => [Visit\VisitsStatsHelper::class], + Action\ShortUrl\ListShortUrlsAction::class => [Service\ShortUrlService::class, 'config.url_shortener.domain'], + Action\ShortUrl\EditShortUrlTagsAction::class => [Service\ShortUrlService::class], + Action\Tag\ListTagsAction::class => [Service\Tag\TagService::class], + Action\Tag\DeleteTagsAction::class => [Service\Tag\TagService::class], + Action\Tag\CreateTagsAction::class => [Service\Tag\TagService::class], + Action\Tag\UpdateTagAction::class => [Service\Tag\TagService::class], Middleware\ShortUrl\DropDefaultDomainFromRequestMiddleware::class => ['config.url_shortener.domain.hostname'], Middleware\ShortUrl\DefaultShortCodesLengthMiddleware::class => [ diff --git a/module/Rest/src/Action/AbstractRestAction.php b/module/Rest/src/Action/AbstractRestAction.php index 589e2d0e..da8b6d80 100644 --- a/module/Rest/src/Action/AbstractRestAction.php +++ b/module/Rest/src/Action/AbstractRestAction.php @@ -7,8 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action; use Fig\Http\Message\RequestMethodInterface; use Fig\Http\Message\StatusCodeInterface; use Psr\Http\Server\RequestHandlerInterface; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; use function array_merge; @@ -17,13 +15,6 @@ abstract class AbstractRestAction implements RequestHandlerInterface, RequestMet protected const ROUTE_PATH = ''; protected const ROUTE_ALLOWED_METHODS = []; - protected LoggerInterface $logger; - - public function __construct(?LoggerInterface $logger = null) - { - $this->logger = $logger ?? new NullLogger(); - } - public static function getRouteDef(array $prevMiddleware = [], array $postMiddleware = []): array { return [ diff --git a/module/Rest/src/Action/HealthAction.php b/module/Rest/src/Action/HealthAction.php index ef1b6b88..ef89da64 100644 --- a/module/Rest/src/Action/HealthAction.php +++ b/module/Rest/src/Action/HealthAction.php @@ -8,7 +8,6 @@ use Doctrine\ORM\EntityManagerInterface; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Options\AppOptions; use Throwable; @@ -24,9 +23,8 @@ class HealthAction extends AbstractRestAction private EntityManagerInterface $em; private AppOptions $options; - public function __construct(EntityManagerInterface $em, AppOptions $options, ?LoggerInterface $logger = null) + public function __construct(EntityManagerInterface $em, AppOptions $options) { - parent::__construct($logger); $this->em = $em; $this->options = $options; } diff --git a/module/Rest/src/Action/MercureInfoAction.php b/module/Rest/src/Action/MercureInfoAction.php index bad4cb9c..75893ab9 100644 --- a/module/Rest/src/Action/MercureInfoAction.php +++ b/module/Rest/src/Action/MercureInfoAction.php @@ -8,7 +8,6 @@ use Cake\Chronos\Chronos; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\Mercure\JwtProviderInterface; use Shlinkio\Shlink\Rest\Exception\MercureException; use Throwable; @@ -23,12 +22,8 @@ class MercureInfoAction extends AbstractRestAction private JwtProviderInterface $jwtProvider; private array $mercureConfig; - public function __construct( - JwtProviderInterface $jwtProvider, - array $mercureConfig, - ?LoggerInterface $logger = null - ) { - parent::__construct($logger); + public function __construct(JwtProviderInterface $jwtProvider, array $mercureConfig) + { $this->jwtProvider = $jwtProvider; $this->mercureConfig = $mercureConfig; } diff --git a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index 3335e1fa..feed626d 100644 --- a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -7,7 +7,6 @@ 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 Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Model\CreateShortUrlData; use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; @@ -19,12 +18,8 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction private UrlShortenerInterface $urlShortener; private array $domainConfig; - public function __construct( - UrlShortenerInterface $urlShortener, - array $domainConfig, - ?LoggerInterface $logger = null - ) { - parent::__construct($logger); + public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig) + { $this->urlShortener = $urlShortener; $this->domainConfig = $domainConfig; } diff --git a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php index d86c60e9..bd5b487e 100644 --- a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\ShortUrl; use Laminas\Diactoros\Response\EmptyResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; @@ -19,9 +18,8 @@ class DeleteShortUrlAction extends AbstractRestAction private DeleteShortUrlServiceInterface $deleteShortUrlService; - public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService, ?LoggerInterface $logger = null) + public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService) { - parent::__construct($logger); $this->deleteShortUrlService = $deleteShortUrlService; } diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php index da7012b6..30d95ae1 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\ShortUrl; use Laminas\Diactoros\Response\EmptyResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Model\ShortUrlEdit; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; @@ -20,9 +19,8 @@ class EditShortUrlAction extends AbstractRestAction private ShortUrlServiceInterface $shortUrlService; - public function __construct(ShortUrlServiceInterface $shortUrlService, ?LoggerInterface $logger = null) + public function __construct(ShortUrlServiceInterface $shortUrlService) { - parent::__construct($logger); $this->shortUrlService = $shortUrlService; } diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php index 0a48d986..def36d6c 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php @@ -7,7 +7,6 @@ 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 Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; @@ -20,9 +19,8 @@ class EditShortUrlTagsAction extends AbstractRestAction private ShortUrlServiceInterface $shortUrlService; - public function __construct(ShortUrlServiceInterface $shortUrlService, ?LoggerInterface $logger = null) + public function __construct(ShortUrlServiceInterface $shortUrlService) { - parent::__construct($logger); $this->shortUrlService = $shortUrlService; } diff --git a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php index 5801eeec..10a0effc 100644 --- a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php +++ b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php @@ -7,7 +7,6 @@ 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 Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait; use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; @@ -24,12 +23,8 @@ class ListShortUrlsAction extends AbstractRestAction private ShortUrlServiceInterface $shortUrlService; private array $domainConfig; - public function __construct( - ShortUrlServiceInterface $shortUrlService, - array $domainConfig, - ?LoggerInterface $logger = null - ) { - parent::__construct($logger); + public function __construct(ShortUrlServiceInterface $shortUrlService, array $domainConfig) + { $this->shortUrlService = $shortUrlService; $this->domainConfig = $domainConfig; } diff --git a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php index 41cd2b2d..9c2cb3e4 100644 --- a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php @@ -7,7 +7,6 @@ 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 Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface; use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer; @@ -21,12 +20,8 @@ class ResolveShortUrlAction extends AbstractRestAction private ShortUrlResolverInterface $urlResolver; private array $domainConfig; - public function __construct( - ShortUrlResolverInterface $urlResolver, - array $domainConfig, - ?LoggerInterface $logger = null - ) { - parent::__construct($logger); + public function __construct(ShortUrlResolverInterface $urlResolver, array $domainConfig) + { $this->urlResolver = $urlResolver; $this->domainConfig = $domainConfig; } diff --git a/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php index e754e3ad..daeb3d04 100644 --- a/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\Rest\Action\ShortUrl; use Laminas\Diactoros\Uri; use Psr\Http\Message\ServerRequestInterface as Request; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Model\CreateShortUrlData; use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; @@ -22,10 +21,9 @@ class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction public function __construct( UrlShortenerInterface $urlShortener, ApiKeyServiceInterface $apiKeyService, - array $domainConfig, - ?LoggerInterface $logger = null + array $domainConfig ) { - parent::__construct($urlShortener, $domainConfig, $logger); + parent::__construct($urlShortener, $domainConfig); $this->apiKeyService = $apiKeyService; } diff --git a/module/Rest/src/Action/Tag/CreateTagsAction.php b/module/Rest/src/Action/Tag/CreateTagsAction.php index eb4a279b..c481b463 100644 --- a/module/Rest/src/Action/Tag/CreateTagsAction.php +++ b/module/Rest/src/Action/Tag/CreateTagsAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\Tag; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; @@ -18,9 +17,8 @@ class CreateTagsAction extends AbstractRestAction private TagServiceInterface $tagService; - public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) + public function __construct(TagServiceInterface $tagService) { - parent::__construct($logger); $this->tagService = $tagService; } diff --git a/module/Rest/src/Action/Tag/DeleteTagsAction.php b/module/Rest/src/Action/Tag/DeleteTagsAction.php index b8bedab9..5002eba0 100644 --- a/module/Rest/src/Action/Tag/DeleteTagsAction.php +++ b/module/Rest/src/Action/Tag/DeleteTagsAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\Tag; use Laminas\Diactoros\Response\EmptyResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; @@ -18,9 +17,8 @@ class DeleteTagsAction extends AbstractRestAction private TagServiceInterface $tagService; - public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) + public function __construct(TagServiceInterface $tagService) { - parent::__construct($logger); $this->tagService = $tagService; } diff --git a/module/Rest/src/Action/Tag/ListTagsAction.php b/module/Rest/src/Action/Tag/ListTagsAction.php index 7cc7e063..7211bce6 100644 --- a/module/Rest/src/Action/Tag/ListTagsAction.php +++ b/module/Rest/src/Action/Tag/ListTagsAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\Tag; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; @@ -18,9 +17,8 @@ class ListTagsAction extends AbstractRestAction private TagServiceInterface $tagService; - public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) + public function __construct(TagServiceInterface $tagService) { - parent::__construct($logger); $this->tagService = $tagService; } diff --git a/module/Rest/src/Action/Tag/UpdateTagAction.php b/module/Rest/src/Action/Tag/UpdateTagAction.php index 6fb72e01..de5eb476 100644 --- a/module/Rest/src/Action/Tag/UpdateTagAction.php +++ b/module/Rest/src/Action/Tag/UpdateTagAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\Tag; use Laminas\Diactoros\Response\EmptyResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; @@ -19,9 +18,8 @@ class UpdateTagAction extends AbstractRestAction private TagServiceInterface $tagService; - public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) + public function __construct(TagServiceInterface $tagService) { - parent::__construct($logger); $this->tagService = $tagService; } diff --git a/module/Rest/src/Action/Visit/GlobalVisitsAction.php b/module/Rest/src/Action/Visit/GlobalVisitsAction.php index 1946e222..a27412b2 100644 --- a/module/Rest/src/Action/Visit/GlobalVisitsAction.php +++ b/module/Rest/src/Action/Visit/GlobalVisitsAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\Visit; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; @@ -18,9 +17,8 @@ class GlobalVisitsAction extends AbstractRestAction private VisitsStatsHelperInterface $statsHelper; - public function __construct(VisitsStatsHelperInterface $statsHelper, ?LoggerInterface $logger = null) + public function __construct(VisitsStatsHelperInterface $statsHelper) { - parent::__construct($logger); $this->statsHelper = $statsHelper; } diff --git a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php index f7f0224a..92a7e873 100644 --- a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php +++ b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\Rest\Action\Visit; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\VisitsParams; @@ -23,9 +22,8 @@ class ShortUrlVisitsAction extends AbstractRestAction private VisitsTrackerInterface $visitsTracker; - public function __construct(VisitsTrackerInterface $visitsTracker, ?LoggerInterface $logger = null) + public function __construct(VisitsTrackerInterface $visitsTracker) { - parent::__construct($logger); $this->visitsTracker = $visitsTracker; }