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

[9.x] Add new wrap string helper #41455

Merged
merged 3 commits into from Mar 13, 2022

Conversation

hebinet
Copy link
Contributor

@hebinet hebinet commented Mar 12, 2022

This PR adds a new wrap string helper.

Usage

Str:wrap('value')->wrap('"');
Str::of('value')->wrap('"');
str('value')->wrap('"');

// Outputs: "value"

Str:wrap('is', 'This ', ' me!');
Str::of('is')->wrap('This ', ' me!');
str('is')->wrap('This ', ' me!');

// Outputs: This is me!

Why do I think this is usefull?
Lately I had a Stringable class and modified its value like this:

$string = Str::of($path)
  ->lower()
  ->replaceLast('/')
  ->replaceFirst($host);

And I couldn't incorporate the wrapping fluently and had to do something like this:

$string = '"'.$string.'"';

...to further modify the string.

@taylorotwell taylorotwell merged commit 1355f4f into laravel:9.x Mar 13, 2022
@TechyMS
Copy link

TechyMS commented Mar 28, 2022

I think colon(':') is missing from Str:wrap.

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.

None yet

3 participants