Skip to content

Commit

Permalink
Fix #19384: Normalize setBodyParams() and getBodyParam() in `yii\…
Browse files Browse the repository at this point in the history
…web\Request`
  • Loading branch information
WinterSilence authored May 23, 2022
1 parent 41f7986 commit e39e744
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Yii Framework 2 Change Log
- Bug #19237: Fix OCI PHP 8.1 passing `null` to trim() (longthanhtran)
- Bug #19312: Fix PHP 8.1 error when passing null to `yii\helpers\BaseInflector` (WinterSilence)
- Bug #19368: Fix PHP 8.1 error when `$fileMimeType` is `null` in `yii\validators\FileValidator::validateMimeType()` (bizley)
- Enh #19384: Normalize `setBodyParams()` and `getBodyParam()` in `yii\web\Request` (WinterSilence, albertborsos)
- Bug #19386: Fix recursive calling `yii\helpers\BaseArrayHelper::htmlDecode()` (WinterSilence)


Expand Down
8 changes: 5 additions & 3 deletions framework/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ public function getBodyParams()

/**
* Sets the request body parameters.
* @param array $values the request body parameters (name-value pairs)
* @see getBodyParam()
*
* @param array|object $values the request body parameters (name-value pairs)
* @see getBodyParams()
*/
public function setBodyParams($values)
Expand All @@ -608,7 +608,9 @@ public function setBodyParams($values)

/**
* Returns the named request body parameter value.
*
* If the parameter does not exist, the second parameter passed to this method will be returned.
*
* @param string $name the parameter name
* @param mixed $defaultValue the default parameter value if the parameter does not exist.
* @return mixed the parameter value
Expand All @@ -622,7 +624,7 @@ public function getBodyParam($name, $defaultValue = null)
if (is_object($params)) {
// unable to use `ArrayHelper::getValue()` due to different dots in key logic and lack of exception handling
try {
return $params->{$name};
return isset($params->{$name}) ? $params->{$name} : $defaultValue;
} catch (\Exception $e) {
return $defaultValue;
}
Expand Down

0 comments on commit e39e744

Please sign in to comment.