*/
class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
{
- /**
- * @var array|null
- */
private $attributes;
-
- /**
- * @var bool
- */
private $lowerCamelCase;
/**
*/
public function normalize($propertyName)
{
- if (null === $this->attributes || in_array($propertyName, $this->attributes)) {
- $lcPropertyName = lcfirst($propertyName);
- $snakeCasedName = '';
-
- $len = strlen($lcPropertyName);
- for ($i = 0; $i < $len; ++$i) {
- if (ctype_upper($lcPropertyName[$i])) {
- $snakeCasedName .= '_'.strtolower($lcPropertyName[$i]);
- } else {
- $snakeCasedName .= strtolower($lcPropertyName[$i]);
- }
- }
-
- return $snakeCasedName;
+ if (null === $this->attributes || \in_array($propertyName, $this->attributes)) {
+ return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
}
return $propertyName;
$camelCasedName = lcfirst($camelCasedName);
}
- if (null === $this->attributes || in_array($camelCasedName, $this->attributes)) {
+ if (null === $this->attributes || \in_array($camelCasedName, $this->attributes)) {
return $camelCasedName;
}