-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[8.x] Add Str::pipe & make Stringable tappable #36017
[8.x] Add Str::pipe & make Stringable tappable #36017
Conversation
Maybe just make it tappable is enough? |
@antonkomarev
Edited: A same example write without this will be like: $str = 'foo > bar';
$str = htmlentities($str)
Log::info('Origin str:' . $str);
$str = md5($str); This small helper add the ability to add huge flexibility while we can have the fluent Stringable already does. |
Again I cry 😢 Why does this work differently than every other
Wrapping the returned value in a new There very well may be a need for the method in this PR, but it should be named something else. Maybe |
Hi @JosephSilber , I agree that the naming is misleading. |
I agree that using the word |
The framework/src/Illuminate/Collections/Traits/EnumeratesValues.php Lines 694 to 703 in 4a6bdbb
No one ever thought of forcing users to return an array, and wrapping the returned value in a |
Actually, I just realized that this is a simple That way So yes, |
@JosephSilber I don't know if renaming current method is a good idea. But we can introduce break change in next major version, to stop wrapping return values in We can still maintain a BC compatibility by wrapping primitive public function pipe(callable $callback)
{
$piped = call_user_func($callback, $this);
return is_string($piped) ? new static($piped) : $piped;
} I know this solution still does extra things that shouldn't be done in |
And now I realized: the way it is currently implemented it's not a
Correct, though we should still keep around a version of this method, under a different name.
That would break BC for callbacks that return an object that can be cast to a string. |
This PR add a simple
pipe
method (feel free to suggest other names) that similar toCollection::transform
.I have considered to name it
transform
, buttransform
mutates itself.Usage example:
While
Stringable
is already macroable, often time we only need to run something once without need to register it into global.I also made
Stringable
tappable: