fortrabbit / datafilter

A data validation (sanitation) module for PHP
MIT License
10 stars 4 forks source link

Make error templates more flexible #4

Open micmath opened 11 years ago

micmath commented 11 years ago

As far as I can tell from the documentation, the most flexibility allowed in a custom error template is to provide a static template string with placeholders, like:

'errorTemplate' => "Attribute :attrib: violated rule :rule:"

But it seems like it should be possible to allow for a function to be assigned there as well. That way I can do more complex transformations on the attrib and rule name.

Use Cases:

It seems like you could update the API to accept either a static string template or an anonymous function, so that the following would work.

'errorTemplate' => function ($attrib, $rule) {
    // make whatever transforms on the $attrib and $rule arguments you want
    return "Attribute $attrib violated rule $rule."
}