Add ServerRequest::getParsedBodyParam method

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2021-07-06 12:24:02 -03:00
parent 8e4d6229a9
commit 1a2d7804d2
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
3 changed files with 22 additions and 2 deletions

View File

@ -160,7 +160,7 @@ class VariablesController extends AbstractController
return;
}
$value = (string) $request->getParam('varValue');
$value = (string) $request->getParsedBodyParam('varValue');
$variableName = (string) $vars['name'];
$matches = [];
$variableType = ServerVariablesProvider::getImplementation()->getVariableType($variableName);

View File

@ -315,6 +315,26 @@ class ServerRequest implements ServerRequestInterface
return $default;
}
/**
* @param mixed $default
*
* @return mixed
*/
public function getParsedBodyParam(string $param, $default = null)
{
$postParams = $this->getParsedBody();
if (is_array($postParams) && isset($postParams[$param])) {
return $postParams[$param];
}
if (is_object($postParams) && property_exists($postParams, $param)) {
return $postParams->$param;
}
return $default;
}
public function isPost(): bool
{
return $this->getMethod() === 'POST';

View File

@ -183,7 +183,7 @@ Core::setDatabaseAndTableFromRequest($containerBuilder);
*/
$sql_query = '';
if ($request->isPost()) {
$sql_query = $request->getParam('sql_query', '');
$sql_query = $request->getParsedBodyParam('sql_query', '');
}
$containerBuilder->setParameter('sql_query', $sql_query);