Fix #19384: Normalize setBodyParams() and getBodyParam() in yii\web\Request

This commit is contained in:
Anton
2022-05-23 09:39:33 +03:00
committed by GitHub
parent 41f7986922
commit e39e744b45
2 changed files with 6 additions and 3 deletions

View File

@ -26,6 +26,7 @@ Yii Framework 2 Change Log
- Bug #19237: Fix OCI PHP 8.1 passing `null` to trim() (longthanhtran) - 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 #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) - 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) - Bug #19386: Fix recursive calling `yii\helpers\BaseArrayHelper::htmlDecode()` (WinterSilence)

View File

@ -597,8 +597,8 @@ class Request extends \yii\base\Request
/** /**
* Sets the request body parameters. * 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() * @see getBodyParams()
*/ */
public function setBodyParams($values) public function setBodyParams($values)
@ -608,7 +608,9 @@ class Request extends \yii\base\Request
/** /**
* Returns the named request body parameter value. * Returns the named request body parameter value.
*
* If the parameter does not exist, the second parameter passed to this method will be returned. * If the parameter does not exist, the second parameter passed to this method will be returned.
*
* @param string $name the parameter name * @param string $name the parameter name
* @param mixed $defaultValue the default parameter value if the parameter does not exist. * @param mixed $defaultValue the default parameter value if the parameter does not exist.
* @return mixed the parameter value * @return mixed the parameter value
@ -622,7 +624,7 @@ class Request extends \yii\base\Request
if (is_object($params)) { if (is_object($params)) {
// unable to use `ArrayHelper::getValue()` due to different dots in key logic and lack of exception handling // unable to use `ArrayHelper::getValue()` due to different dots in key logic and lack of exception handling
try { try {
return $params->{$name}; return isset($params->{$name}) ? $params->{$name} : $defaultValue;
} catch (\Exception $e) { } catch (\Exception $e) {
return $defaultValue; return $defaultValue;
} }