Skip to content

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

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
hebinet:add-new-wrap-string-helper
Mar 13, 2022
Merged

taylorotwell merged 3 commits into
laravel:9.xfrom
hebinet:add-new-wrap-string-helper

Conversation

@hebinet

@hebinet hebinet commented Mar 12, 2022

Copy link
Copy Markdown
Contributor

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

TechyMS commented Mar 28, 2022

Copy link
Copy Markdown

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.

3 participants