Use WP-native params to support all REST API request formats
[MAILPOET-4207]
This commit is contained in:
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace MailPoet\Automation\Engine\API;
|
namespace MailPoet\Automation\Engine\API;
|
||||||
|
|
||||||
use MailPoet\Automation\Engine\Exceptions;
|
|
||||||
use WP_REST_Request;
|
use WP_REST_Request;
|
||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
@ -19,33 +18,12 @@ class Request {
|
|||||||
return $this->wpRequest->get_header($key);
|
return $this->wpRequest->get_header($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrlParams(): array {
|
public function getParams(): array {
|
||||||
return $this->wpRequest->get_url_params();
|
return $this->wpRequest->get_params();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrlParam(string $name): ?string {
|
/** @return mixed */
|
||||||
return $this->getUrlParams()[$name] ?? null;
|
public function getParam(string $name) {
|
||||||
}
|
return $this->wpRequest->get_param($name);
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class WorkflowsPostEndpoint extends Endpoint {
|
|||||||
|
|
||||||
public function handle(Request $request): Response {
|
public function handle(Request $request): Response {
|
||||||
// TODO: validation
|
// TODO: validation
|
||||||
$data = $request->getBody();
|
$data = $request->getParams();
|
||||||
$this->createController->createWorkflow($data);
|
$this->createController->createWorkflow($data);
|
||||||
return new Response();
|
return new Response();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user