Rules not exported after non-static rule
jtojnar opened this issue · comments
Version: 3.1.3
Bug Description
Since 1592cf6, no rules after a callback rule are passed to the frontend.
I understand that this is to prevent conflict between filters (which are just impure rules) and other rules but it leads to confusing behaviour, where rules suddenly terminate from frontend point of view, even if the callback is just a pure function.
Steps To Reproduce
test('', function () {
$form = new Form;
$input = $form->addText('text');
$input->addRule(function ($input) {
return true;
});
$input->addRule(Form::EMAIL);
Assert::same([
['op' => ':email', 'msg' => 'Please enter a valid email address.'],
], Helpers::exportRules($input->getRules()));
});
Expected Behavior
I think we should give callbacks passed to addRule
a benefit of a doubt (that they might be pure) and not terminate the rule export.
But yeah, I understand the paranoid point of view (all functions are potentially effectful/impure and we cannot trust them not to modify the control) since PHP cannot distinguish pure and effectful functions.
Possible Solutions
- We could add
isFilter
/impure
property toRule
, set it totrue
inaddFilter
, and terminate export only for impure rules. - The behaviour could be further emphasised in docs and the hack would be recommended: