DeleteTagsAction.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\Rest\Action\Tag;
  4. use Laminas\Diactoros\Response\EmptyResponse;
  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 DeleteTagsAction extends AbstractRestAction
  11. {
  12. protected const ROUTE_PATH = '/tags';
  13. protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE];
  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. */
  26. public function handle(ServerRequestInterface $request): ResponseInterface
  27. {
  28. $query = $request->getQueryParams();
  29. $tags = $query['tags'] ?? [];
  30. $this->tagService->deleteTags($tags);
  31. return new EmptyResponse();
  32. }
  33. }