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

[11.x] Rework Context::stackContains with Closures. #52381

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Aug 5, 2024

This PR re-works how Context::stackContains works with closures to make it line up with how Collection::contains works.

Before, the closure passed to Context::stackContains would receive the entire stack. I believe it should be passed each individual item and have a truth test performed on the item.

Context::push('stack-name', 'value-1');
Context::push('stack-name', 'value-2');
Context::push('stack-name', 'value-3');

Context::stackContains('stack-name', function (string $value) {
    // $value will be "value-1" then "value-2" then "value-3"

    return str_ends_with($value, '-2');
});

Previously, the closure received the entire stack.

Context::stackContains('stack-name', function (array $stack) {
    // $value is ["value-1",  "value-2", "value-3"]
});

@@ -360,7 +360,7 @@ public function hiddenStackContains(string $key, mixed $value, bool $strict = fa
}

if ($value instanceof Closure) {
return $value($this->data[$key]);
return collect($this->hidden[$key])->contains($value);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bugfix as well because it was not checking the hidden data.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was already going to notify you about this after I read the other PR 😂

@taylorotwell taylorotwell merged commit c03c298 into laravel:11.x Aug 5, 2024
31 checks passed
@timacdonald timacdonald deleted the context-contains branch August 5, 2024 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants