DeleteShortUrlAction.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
  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\ShortUrl\DeleteShortUrlServiceInterface;
  9. use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
  10. class DeleteShortUrlAction extends AbstractRestAction
  11. {
  12. protected const ROUTE_PATH = '/short-urls/{shortCode}';
  13. protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE];
  14. private DeleteShortUrlServiceInterface $deleteShortUrlService;
  15. public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService, ?LoggerInterface $logger = null)
  16. {
  17. parent::__construct($logger);
  18. $this->deleteShortUrlService = $deleteShortUrlService;
  19. }
  20. public function handle(ServerRequestInterface $request): ResponseInterface
  21. {
  22. $shortCode = $request->getAttribute('shortCode', '');
  23. $this->deleteShortUrlService->deleteByShortCode($shortCode);
  24. return new EmptyResponse();
  25. }
  26. }