Skip to content

Commit d96bab4

Browse files
committed
addRule(~Form::REQUIRED) is converted to Form::BLANK and has different meaning than not-required (BC break)
1 parent 816f3df commit d96bab4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Forms/Rules.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function setRequired($value = TRUE)
6464
*/
6565
public function isRequired()
6666
{
67-
return $this->required instanceof Rule ? !$this->required->isNegative : FALSE;
67+
return (bool) $this->required;
6868
}
6969

7070

@@ -281,6 +281,11 @@ private function adjustOperation($rule)
281281
$name = strncmp($rule->validator, ':', 1) ? $rule->validator : 'Form:' . strtoupper($rule->validator);
282282
trigger_error("Negative validation rules such as ~$name are deprecated.", E_USER_DEPRECATED);
283283
}
284+
if ($rule->validator === Form::FILLED) {
285+
$rule->validator = Form::BLANK;
286+
$rule->isNegative = FALSE;
287+
trigger_error('Replace negative validation rule ~Form::FILLED with Form::BLANK.', E_USER_DEPRECATED);
288+
}
284289
}
285290

286291
if (!is_callable($this->getCallback($rule))) {

tests/Forms/Rules.required.phpt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ test(function () { // 'required' is always the first rule
5757

5858
@$rules->addRule(~$form::REQUIRED); // @ - negative rules are deprecated
5959
$items = iterator_to_array($rules);
60-
Assert::count(2, $items);
61-
Assert::same(Form::REQUIRED, $items[0]->validator);
62-
Assert::true($items[0]->isNegative);
63-
Assert::same(Form::EMAIL, $items[1]->validator);
60+
Assert::count(3, $items);
61+
Assert::same(Form::BLANK, $items[2]->validator);
62+
Assert::false($items[2]->isNegative);
6463

6564
Assert::false($rules->validate());
66-
Assert::same(['Please enter a valid email address.'], $input->getErrors());
65+
Assert::same(['This field is required.'], $input->getErrors());
6766
});
6867

6968

0 commit comments

Comments
 (0)