Skip to content

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
$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) 
  }
}

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