-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Support conditionables that get condition from target object #43449
[9.x] Support conditionables that get condition from target object #43449
Conversation
* @return void | ||
*/ | ||
public function __construct($target, $condition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this is a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right that it is a breaking change, though isn't it considered part of the internal API?
* @param (callable($this, TWhenParameter): TWhenReturnType)|null $callback | ||
* @param (callable($this, TWhenParameter): TWhenReturnType)|null $default | ||
* @return $this|TWhenReturnType | ||
*/ | ||
public function when($value, callable $callback = null, callable $default = null) | ||
public function when($value = null, callable $callback = null, callable $default = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the method signature here is a breaking change.
…aravel#43449) * Support conditionables that get condition from target object * Style * Rename method to be more explicit * Add test & support for properties * Update SupportConditionableTest.php * formatting Co-authored-by: Taylor Otwell <[email protected]>
This PR allows people to use the
->when()
and->unless()
methods without passing in any parameters.Currently, people are required to pass in the condition as the first parameter:
The
Conditionable
will execute the closure and store that as the condition. The next method call ("makeDirectory") will be proxied to the original object based on that condition.This PR allows to create a proxy without an initial condition. The first method call to the proxy will become the condition, and the second call will be proxied to the original object based on that condition.
With this change, the above example would become:
(In this example I'll assume that the #43450 PR gets merged first, but you certainly can get the general idea.)
Thanks!