ListTagsAction.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\Rest\Action\Tag;
  4. use Laminas\Diactoros\Response\JsonResponse;
  5. use Psr\Http\Message\ResponseInterface;
  6. use Psr\Http\Message\ServerRequestInterface;
  7. use Psr\Log\LoggerInterface;
  8. use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
  9. use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
  10. class ListTagsAction extends AbstractRestAction
  11. {
  12. protected const ROUTE_PATH = '/tags';
  13. protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
  14. private TagServiceInterface $tagService;
  15. public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null)
  16. {
  17. parent::__construct($logger);
  18. $this->tagService = $tagService;
  19. }
  20. /**
  21. * Process an incoming server request and return a response, optionally delegating
  22. * to the next middleware component to create the response.
  23. *
  24. *
  25. * @throws \InvalidArgumentException
  26. */
  27. public function handle(ServerRequestInterface $request): ResponseInterface
  28. {
  29. return new JsonResponse([
  30. 'tags' => [
  31. 'data' => $this->tagService->listTags(),
  32. ],
  33. ]);
  34. }
  35. }