diff --git a/src/Method/Request.php b/src/Method/Request.php index cc591f7..1cfff22 100644 --- a/src/Method/Request.php +++ b/src/Method/Request.php @@ -7,6 +7,7 @@ use Picea\Extension\Extension, use Picea\Compiler\Context; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ServerRequestInterface; class Request implements Extension { @@ -46,7 +47,7 @@ class Request implements Extension { public function post(? string $variableName = null, $default = null) { - return $variableName === null ? $this->request->getParsedBody() : static::arrayGet($this->request->getParsedBody(), $variableName) ?? $default; + return $variableName === null ? $this->_post() : static::arrayGet($this->_post(), $variableName) ?? $default; } public function request(? string $variableName = null, $default = null) @@ -75,4 +76,19 @@ class Request implements Extension { return null; } } + + protected function _post() : array + { + $post = $this->request->getParsedBody(); + + if ( ! $post ) { + $content = utf8_encode((string) $this->request->getBody()); + + if ( $content && ( $json = json_decode($content, true) ) ) { + $post = $json; + } + } + + return $post ?: []; + } } \ No newline at end of file