mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-07 07:43:12 +08:00
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
|
|
|
|
use Laminas\Diactoros\Response\EmptyResponse;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
|
|
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface;
|
|
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
|
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
|
|
|
|
class DeleteShortUrlAction extends AbstractRestAction
|
|
{
|
|
protected const ROUTE_PATH = '/short-urls/{shortCode}';
|
|
protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE];
|
|
|
|
private DeleteShortUrlServiceInterface $deleteShortUrlService;
|
|
|
|
public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService)
|
|
{
|
|
$this->deleteShortUrlService = $deleteShortUrlService;
|
|
}
|
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
|
{
|
|
$identifier = ShortUrlIdentifier::fromApiRequest($request);
|
|
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
|
|
|
$this->deleteShortUrlService->deleteByShortCode($identifier, false, $apiKey);
|
|
|
|
return new EmptyResponse();
|
|
}
|
|
}
|