You are here

public function CamelCaseToSnakeCaseNameConverter::normalize in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php \Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::normalize()

Converts a property name to its normalized value.

Parameters

string $propertyName:

Return value

string

Overrides NameConverterInterface::normalize

File

vendor/symfony/serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php, line 43

Class

CamelCaseToSnakeCaseNameConverter
CamelCase to Underscore name converter.

Namespace

Symfony\Component\Serializer\NameConverter

Code

public function normalize($propertyName) {
  if (null === $this->attributes || in_array($propertyName, $this->attributes)) {
    $snakeCasedName = '';
    $len = strlen($propertyName);
    for ($i = 0; $i < $len; ++$i) {
      if (ctype_upper($propertyName[$i])) {
        $snakeCasedName .= '_' . strtolower($propertyName[$i]);
      }
      else {
        $snakeCasedName .= strtolower($propertyName[$i]);
      }
    }
    return $snakeCasedName;
  }
  return $propertyName;
}