From a06a8af0d502ca7cc09e87c1bb35434c3d7bffe6 Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Tue, 12 Apr 2022 13:19:00 +0200 Subject: [PATCH] Use WP-native params to support all REST API request formats [MAILPOET-4207] --- .../lib/Automation/Engine/API/Request.php | 32 +++---------------- .../Workflows/WorkflowsPostEndpoint.php | 2 +- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/mailpoet/lib/Automation/Engine/API/Request.php b/mailpoet/lib/Automation/Engine/API/Request.php index 962efc8ce9..03f2947747 100644 --- a/mailpoet/lib/Automation/Engine/API/Request.php +++ b/mailpoet/lib/Automation/Engine/API/Request.php @@ -2,7 +2,6 @@ namespace MailPoet\Automation\Engine\API; -use MailPoet\Automation\Engine\Exceptions; use WP_REST_Request; class Request { @@ -19,33 +18,12 @@ class Request { return $this->wpRequest->get_header($key); } - public function getUrlParams(): array { - return $this->wpRequest->get_url_params(); + public function getParams(): array { + return $this->wpRequest->get_params(); } - public function getUrlParam(string $name): ?string { - return $this->getUrlParams()[$name] ?? null; - } - - public function getQueryParams(): array { - return $this->wpRequest->get_query_params(); - } - - public function getQueryParam(string $name): ?string { - return $this->getQueryParams()[$name] ?? null; - } - - public function getBody(): array { - $json = $this->wpRequest->get_json_params(); - - /* @phpstan-ignore-next-line hotfix for missing 'null' in WP annotation */ - if ($json === null) { - throw Exceptions::apiNoJsonBody(); - } - return $json; - } - - public function getRawBody(): string { - return $this->wpRequest->get_body(); + /** @return mixed */ + public function getParam(string $name) { + return $this->wpRequest->get_param($name); } } diff --git a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php index db14aa8b6b..5aaa9e5b7f 100644 --- a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php +++ b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPostEndpoint.php @@ -19,7 +19,7 @@ class WorkflowsPostEndpoint extends Endpoint { public function handle(Request $request): Response { // TODO: validation - $data = $request->getBody(); + $data = $request->getParams(); $this->createController->createWorkflow($data); return new Response(); }