Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

gsteel
Copy link
Member

@gsteel gsteel commented Jul 30, 2024

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.

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.

Signed-off-by: George Steel <[email protected]>
@gsteel
Copy link
Member Author

gsteel commented Jul 30, 2024

Partially addresses #96

Copy link
Member

@froschdesign froschdesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

@gsteel gsteel self-assigned this Jul 31, 2024
@gsteel gsteel merged commit 2a52bc0 into laminas:3.0.x Jul 31, 2024
16 checks passed
@gsteel gsteel deleted the v3/callback-simplification branch July 31, 2024 08:16
gsteel added a commit to gsteel/laminas-validator that referenced this pull request Jul 31, 2024
gsteel added a commit to gsteel/laminas-validator that referenced this pull request Jul 31, 2024
gsteel added a commit to gsteel/laminas-validator that referenced this pull request Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants