Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Yii Framework 2 Change Log
- 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 #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)
- 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)
Expand Down
15 changes: 12 additions & 3 deletions framework/validators/CompareValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@ class CompareValidator extends Validator
*/
public $compareAttribute;
/**
* @var mixed the constant value to be compared with. When both this property
* and [[compareAttribute]] are set, this property takes precedence.
* @var mixed the constant value to be compared with or an anonymous function
* 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
*/
public $compareValue;
Expand Down Expand Up @@ -144,7 +153,7 @@ public function validateAttribute($model, $attribute)
}
if ($this->compareValue !== null) {
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;
} else {
Expand Down
Loading