Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / serializer / NameConverter / CamelCaseToSnakeCaseNameConverter.php
index 508881e84c2a75f59efe45b7ceefca8dc0ac054f..9c3f318edd1d4df06bad1aa1432b9d3c4449ba9b 100644 (file)
@@ -18,14 +18,7 @@ namespace Symfony\Component\Serializer\NameConverter;
  */
 class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
 {
-    /**
-     * @var array|null
-     */
     private $attributes;
-
-    /**
-     * @var bool
-     */
     private $lowerCamelCase;
 
     /**
@@ -43,20 +36,8 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
      */
     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;
@@ -75,7 +56,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
             $camelCasedName = lcfirst($camelCasedName);
         }
 
-        if (null === $this->attributes || in_array($camelCasedName, $this->attributes)) {
+        if (null === $this->attributes || \in_array($camelCasedName, $this->attributes)) {
             return $camelCasedName;
         }