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

[5.8] adds Str::containsAll() method #28806

Merged
merged 2 commits into from
Jun 12, 2019
Merged

[5.8] adds Str::containsAll() method #28806

merged 2 commits into from
Jun 12, 2019

Conversation

chrisbbreuer
Copy link
Contributor

@chrisbbreuer chrisbbreuer commented Jun 11, 2019

Hi everyone,

As discussed here #28688 and #28695 - in order to avoid a breaking change, I abstracted it into a new method called containsAll() and I am using contains() to check whether the value is contained inside the string.

Every now and then I run into a dilemma where I want to check if an array of values is contained within a string.

This adds the functionality to check for all array values inside a string.

Check out the tests to see all the supported scenarios.

I hope you guys find this useful, too 🙂

Chris

* @param string|array $needles
* @return bool
*/
public static function containsAll($haystack, $needles)
Copy link
Member

@timacdonald timacdonald Jun 12, 2019

Choose a reason for hiding this comment

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

I'd would think this could explicitly require an array for $needles. Otherwise you would just use Str::contains() for a single item.

i.e. I'm not sure Str::containsAll($names, 'Tim'); makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, Tim. I have asked myself the same question on whether a string should or should not be allowed. I thought it wouldn't "hurt" to keep the functionality and possibly could come in handy at times.

But you're right; logically, Str::contains() would be a more suitable call for that.

Definitely open for a discussion here on whether to keep or to remove it!

@taylorotwell taylorotwell merged commit a986126 into laravel:5.8 Jun 12, 2019
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