laminas / laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria
https://docs.laminas.dev/laminas-validator/
BSD 3-Clause "New" or "Revised" License
126 stars 55 forks source link

Firm up Callback arguments and document `$context` parameter. #379

Closed gsteel closed 1 month ago

gsteel commented 1 month ago

Changes the Callback validator so that the callable always receives (mixed $value, array $context, ...$otherArgs) - this stabilizes the args for all environments, i.e. standalone usage and when part of input-filter etc.

Because the Callback validator is used internally, by the CreditCard validator, this also affects the signature of the service option to include context and declares the $context param in CreditCard::isValid() so that it can correctly be passed to the composed callback validator.

Will need to document this change in #253

Edit: a bit more clarity…

Previously, the callback might receive (mixed $value, ...$userDefinedArgs) or (mixed $value, array $context, ...$userDefinedArgs) depending on whether the context was given to Callback::isValid() as the second param. This is difficult to document and hard to understand when the given arguments might differ.

This change means that the required signature of the callback is consistent at all times, but $context might be === [] in standalone usage.

gsteel commented 1 month ago

Partially addresses #96