Skip to content

Commit

Permalink
Fix CamelToSnakeCase.php
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Feb 16, 2024
1 parent 6f61257 commit 116f6fe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BinderObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected function bindObjectInternal($source, $target, ?PropertyPatternInterfac

foreach ($sourceArray as $propName => $value) {
if (!is_null($propertyPattern)) {
$propName = $propertyPattern->prepare($propName);
if (!is_null($propertyPattern->getCallback())) {
$propName = preg_replace_callback($propertyPattern->getRegEx(), $propertyPattern->getCallback(), $propName);
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/PropertyPattern/CamelToSnakeCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ public function getReplacement(): ?string
{
return null;
}

public function prepare($value)
{
return $value;
}
}
2 changes: 2 additions & 0 deletions src/PropertyPattern/PropertyPatternInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public function getRegEx(): string;
public function getCallback(): ?Closure;

public function getReplacement(): ?string;

public function prepare($value);
}
5 changes: 5 additions & 0 deletions src/PropertyPattern/SnakeToCamelCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ public function getReplacement(): ?string
{
return null;
}

public function prepare($value)
{
return strtolower($value);
}
}

0 comments on commit 116f6fe

Please sign in to comment.