2 Commits
Author SHA1 Message Date
mcndave 531f786747 Merge branch 'master' of https://git.mcnd.ca/mcndave/picea 2022-06-27 17:29:31 +00:00
mcndave 22e046dfcd - Fixed post() method 2022-06-27 17:28:35 +00:00
+17 -1
View File
@@ -7,6 +7,7 @@ use Picea\Extension\Extension,
use Picea\Compiler\Context; use Picea\Compiler\Context;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
class Request implements Extension { class Request implements Extension {
@@ -46,7 +47,7 @@ class Request implements Extension {
public function post(? string $variableName = null, $default = null) 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) public function request(? string $variableName = null, $default = null)
@@ -75,4 +76,19 @@ class Request implements Extension {
return null; 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 ?: [];
}
} }