diff --git a/Templates/PHP/Model/EnumType.php.tt b/Templates/PHP/Model/EnumType.php.tt
index ee3096e0f..54590f404 100644
--- a/Templates/PHP/Model/EnumType.php.tt
+++ b/Templates/PHP/Model/EnumType.php.tt
@@ -42,7 +42,7 @@ class <#=enumT.Name.ToUpperFirstChar()#> extends Enum
<#
} else {
#>
- const <#= value.Name.ToUnderscore().ToUpper()#> = "<#= value.Name.ToCamelize()#>";
+ const <#= value.Name.ToUnderscorePHPEnum().ToUpper()#> = "<#= value.Name.ToCamelize()#>";
<# }
count++;
}
diff --git a/src/GraphODataTemplateWriter/Extensions/StringExtensions.cs b/src/GraphODataTemplateWriter/Extensions/StringExtensions.cs
index 9b3c4176f..72c1ff5f7 100644
--- a/src/GraphODataTemplateWriter/Extensions/StringExtensions.cs
+++ b/src/GraphODataTemplateWriter/Extensions/StringExtensions.cs
@@ -72,6 +72,27 @@ public static string ToUnderscore(this string input)
return Inflector.Inflector.Underscore(input);
}
+ ///
+ /// Replaces underscores with double underscore, adds underscore between camel
+ /// case, converts hyphens to underscore. It does the same as ToUnderscore but
+ /// adds the double underscore capability.
+ ///
+ ///
+ ///
+ public static string ToUnderscorePHPEnum(this string input)
+ {
+ return Regex.Replace(
+ Regex.Replace(
+ Regex.Replace(
+ Regex.Replace(input, @"([_\s])([A-Z])", "$1_$2"),
+ @"([a-z\d])([A-Z])",
+ "$1_$2"),
+ @"([A-Z]+)([A-Z][a-z])", "$1_$2"),
+ @"[-\s]",
+ "_")
+ .ToLower();
+ }
+
public static string RemoveFromEnd(this string input, string suffix)
{
if (input.EndsWith(suffix))