22
33namespace Greg0ire \Enum ;
44
5- use Doctrine \Common \Inflector \Inflector ;
5+ use Doctrine \Inflector \Inflector ;
6+ use Doctrine \Inflector \InflectorFactory ;
67use Greg0ire \Enum \Exception \InvalidEnumName ;
78use Greg0ire \Enum \Exception \InvalidEnumValue ;
89
@@ -19,6 +20,11 @@ abstract class AbstractEnum
1920
2021 private static $ constCache = [];
2122
23+ /**
24+ * @var Inflector
25+ */
26+ private static $ inflector ;
27+
2228 /**
2329 * Uses reflection to find the constants defined in the class and cache
2430 * them in a local property for performance, before returning them.
@@ -98,7 +104,11 @@ final public static function getClassPrefixedKeys(
98104 ?string $ namespaceSeparator = null
99105 ): array {
100106 $ namespaceSeparator = $ namespaceSeparator ?: static ::$ defaultNamespaceSeparator ;
101- $ classKey = str_replace ('\\' , $ namespaceSeparator , Inflector::tableize (static ::class));
107+ $ classKey = str_replace (
108+ '\\' ,
109+ $ namespaceSeparator ,
110+ self ::inflector ()->tableize (static ::class)
111+ );
102112
103113 $ keys = static ::getKeys (function ($ key ) use ($ namespaceSeparator , $ classKey ) {
104114 return $ classKey .$ namespaceSeparator .$ key ;
@@ -111,6 +121,15 @@ final public static function getClassPrefixedKeys(
111121 return $ keys ;
112122 }
113123
124+ private static function inflector (): Inflector
125+ {
126+ if (!isset (self ::$ inflector )) {
127+ self ::$ inflector = InflectorFactory::create ()->build ();
128+ }
129+
130+ return self ::$ inflector ;
131+ }
132+
114133 /**
115134 * Checks whether a constant with this name is defined.
116135 */
0 commit comments