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] Allow customizing TrimStrings::$except #50901

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

grohiro
Copy link
Contributor

@grohiro grohiro commented Apr 3, 2024

I've noticed that TrimStrings::$except does not support array values like users.*.email.
This pull request extracts new methods to allow developers to customize this behavior.
This change is fully backwards compatible.

@grohiro grohiro marked this pull request as ready for review April 3, 2024 11:04
@grohiro grohiro changed the title Allow customizing TrimStrings::$except [11.x] Allow customizing TrimStrings::$except Apr 3, 2024
@@ -62,13 +62,21 @@ protected function transform($key, $value)
{
$except = array_merge($this->except, static::$neverTrim);

if (in_array($key, $except, true) || ! is_string($value)) {
if ($this->skipTrim($key, $except) || ! is_string($value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You've just moved in_array to a function, just this!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@milwad-dev
Yes, this is a hook point. You can customize the behavior like this:

class TrimArrayStrings extends TrimStrings
{
  protected function skipTrim($key, $except)
  {
    return parent::skipTrim($key, $except) || $this->skipMoreComplexCondition($key, $except) 
  }
}

@taylorotwell taylorotwell merged commit 95aa2fe into laravel:11.x Apr 3, 2024
26 of 28 checks passed
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