Astrotomic / Astrotomic/php-conditional-proxy
Pass conditional value to callback
- Dominant language
- PHP
- Stars
- 32
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
The `when()` method accepts a value it will use as condition. It would be great to be able to access this value in the callback as argument as it's more common to do something like `$mail->when($user->email, fn($mail, $email) => $mail->to($email))` then using `empty()` function or call the value retriever again in the callback.
Because we already pass the instance `when()` is called on as first argument and this change shouldn't be breaking we should pass the value as second argument to the callback. As PHP ignores additional arguments this change isn't breaking.
This should only be applied to the callback way and not the higher-order-proxy as we have no idea to which argument we should pass the value and this could also be breaking.
Contributor guide
Research direction
Start at the `when()` implementation and trace the callback-based path, distinguishing it from the higher-order proxy path. Update the callback behavior so its second argument is the condition value while preserving the existing first argument and proxy behavior, then run the relevant test suite to verify both paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100