[9.x] Support conditionables that get condition from target object#43449
Merged
taylorotwell merged 6 commits intoJul 29, 2022
Merged
Conversation
driesvints
reviewed
Jul 28, 2022
| * @param bool $condition | ||
| * @return void | ||
| */ | ||
| public function __construct($target, $condition) |
Member
There was a problem hiding this comment.
Removing this is a breaking change.
Contributor
Author
There was a problem hiding this comment.
You are right that it is a breaking change, though isn't it considered part of the internal API?
driesvints
reviewed
Jul 28, 2022
| * @return $this|TWhenReturnType | ||
| */ | ||
| public function when($value, callable $callback = null, callable $default = null) | ||
| public function when($value = null, callable $callback = null, callable $default = null) |
Member
There was a problem hiding this comment.
Changing the method signature here is a breaking change.
Ken-vdE
pushed a commit
to Ken-vdE/framework
that referenced
this pull request
Aug 9, 2022
…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 <taylor@laravel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Conditionablewill 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!