shortUrlService = $shortUrlService; } /** * Process an incoming server request and return a response, optionally delegating * to the next middleware component to create the response. * * @param ServerRequestInterface $request * * @return ResponseInterface * @throws \InvalidArgumentException */ public function handle(ServerRequestInterface $request): ResponseInterface { $postData = (array) $request->getParsedBody(); $shortCode = $request->getAttribute('shortCode', ''); try { $this->shortUrlService->updateMetadataByShortCode( $shortCode, ShortUrlMeta::createFromRawData($postData) ); return new EmptyResponse(); } catch (Exception\ValidationException $e) { $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => 'Provided data is invalid.', ], self::STATUS_BAD_REQUEST); } } }