function CamelCaseToSnakeCaseNameConverter::denormalize
Parameters
class-string|null $class:
string|null $format:
array<string, mixed> $context:
Overrides NameConverterInterface::denormalize
File
-
vendor/
symfony/ serializer/ NameConverter/ CamelCaseToSnakeCaseNameConverter.php, line 58
Class
- CamelCaseToSnakeCaseNameConverter
- CamelCase to Underscore name converter.
Namespace
Symfony\Component\Serializer\NameConverterCode
public function denormalize(string $propertyName) : string {
$class = 1 < \func_num_args() ? func_get_arg(1) : null;
$format = 2 < \func_num_args() ? func_get_arg(2) : null;
$context = 3 < \func_num_args() ? func_get_arg(3) : [];
if (($context[self::REQUIRE_SNAKE_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) {
throw new UnexpectedPropertyException($propertyName);
}
$camelCasedName = preg_replace_callback('/(^|_|\\.)+(.)/', fn($match) => ('.' === $match[1] ? '_' : '') . strtoupper($match[2]), $propertyName);
if ($this->lowerCamelCase) {
$camelCasedName = lcfirst($camelCasedName);
}
if (null === $this->attributes || \in_array($camelCasedName, $this->attributes, true)) {
return $camelCasedName;
}
return $propertyName;
}