Files
shlink/module/Rest/src/Action/ShortUrl/CreateShortUrlAction.php
2024-12-02 09:16:15 +01:00

29 lines
965 B
PHP

<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Core\Exception\ValidationException;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
class CreateShortUrlAction extends AbstractCreateShortUrlAction
{
protected const string ROUTE_PATH = '/short-urls';
protected const array ROUTE_ALLOWED_METHODS = [self::METHOD_POST];
/**
* @throws ValidationException
*/
protected function buildShortUrlData(Request $request): ShortUrlCreation
{
$payload = (array) $request->getParsedBody();
$payload[ShortUrlInputFilter::API_KEY] = AuthenticationMiddleware::apiKeyFromRequest($request);
return ShortUrlCreation::fromRawData($payload, $this->urlShortenerOptions);
}
}