mirror of
https://github.com/yiisoft/yii2.git
synced 2025-12-13 01:41:42 +08:00
Fix #20642: Pass $model and $attribute in Compare Validator's compareValue property closure
This commit is contained in:
@@ -73,6 +73,7 @@ Yii Framework 2 Change Log
|
|||||||
- Bug #20639: Add missing generics in `yii\web` namespace (mspirkov)
|
- Bug #20639: Add missing generics in `yii\web` namespace (mspirkov)
|
||||||
- Bug #20645: Add missing generics in `yii\helpers` and `yii\test` namespaces. Fix PHPDoc annotations in `ArrayAccessTrait` (mspirkov)
|
- Bug #20645: Add missing generics in `yii\helpers` and `yii\test` namespaces. Fix PHPDoc annotations in `ArrayAccessTrait` (mspirkov)
|
||||||
- Bug #20640: Fix `@param` annotation for `$block` in `yii\console\Markdown::renderParagraph()` (mspirkov)
|
- Bug #20640: Fix `@param` annotation for `$block` in `yii\console\Markdown::renderParagraph()` (mspirkov)
|
||||||
|
- Enh #20642: Pass `$model` and `$attribute` in Compare Validator's compareValue property closure (samuelrajan747)
|
||||||
- Enh #20650: Add PHPStan/Psalm annotations for `yii\di\Container` (mspirkov)
|
- Enh #20650: Add PHPStan/Psalm annotations for `yii\di\Container` (mspirkov)
|
||||||
- Bug #20654: Add missing generics in `yii\db` namespace. Fix PHPDoc annotations in `yii\db\ArrayExpression` (mspirkov)
|
- Bug #20654: Add missing generics in `yii\db` namespace. Fix PHPDoc annotations in `yii\db\ArrayExpression` (mspirkov)
|
||||||
- Bug #20651: Add missing generics in `yii\filters` namespace (mspirkov)
|
- Bug #20651: Add missing generics in `yii\filters` namespace (mspirkov)
|
||||||
|
|||||||
@@ -57,8 +57,17 @@ class CompareValidator extends Validator
|
|||||||
*/
|
*/
|
||||||
public $compareAttribute;
|
public $compareAttribute;
|
||||||
/**
|
/**
|
||||||
* @var mixed the constant value to be compared with. When both this property
|
* @var mixed the constant value to be compared with or an anonymous function
|
||||||
* and [[compareAttribute]] are set, this property takes precedence.
|
* that returns the constant value. When both this property and
|
||||||
|
* [[compareAttribute]] are set, this property takes precedence.
|
||||||
|
* The signature of the anonymous function should be as follows,
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* function($model, $attribute) {
|
||||||
|
* // compute value to compare with
|
||||||
|
* return $value;
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
* @see compareAttribute
|
* @see compareAttribute
|
||||||
*/
|
*/
|
||||||
public $compareValue;
|
public $compareValue;
|
||||||
@@ -144,7 +153,7 @@ class CompareValidator extends Validator
|
|||||||
}
|
}
|
||||||
if ($this->compareValue !== null) {
|
if ($this->compareValue !== null) {
|
||||||
if ($this->compareValue instanceof \Closure) {
|
if ($this->compareValue instanceof \Closure) {
|
||||||
$this->compareValue = call_user_func($this->compareValue);
|
$this->compareValue = call_user_func($this->compareValue, $model, $attribute);
|
||||||
}
|
}
|
||||||
$compareLabel = $compareValue = $compareValueOrAttribute = $this->compareValue;
|
$compareLabel = $compareValue = $compareValueOrAttribute = $this->compareValue;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user