Skip to content

Commit 85ec22c

Browse files
committed
Use new Inflector API
Fixes #142
1 parent 6065a12 commit 85ec22c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"require": {
2424
"php": "^7.1",
25-
"doctrine/inflector": "^1.0"
25+
"doctrine/inflector": "^1.4 || ^2.0"
2626
},
2727
"conflict": {
2828
"symfony/form": "<3.2 || >=6.0 <999",

src/AbstractEnum.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Greg0ire\Enum;
44

5-
use Doctrine\Common\Inflector\Inflector;
5+
use Doctrine\Inflector\Inflector;
6+
use Doctrine\Inflector\InflectorFactory;
67
use Greg0ire\Enum\Exception\InvalidEnumName;
78
use 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

Comments
 (0)