diff --git a/.travis.yml b/.travis.yml index d9ed36b..9cbd12d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,3 @@ -branches: - only: - - legacy-stable - - master - - unstable - language: php php: diff --git a/composer.json b/composer.json index fb817e7..490e671 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { "php": "^7.1", - "doctrine/inflector": "^1.0" + "doctrine/inflector": "^1.4 || ^2.0" }, "conflict": { "symfony/form": "<3.2 || >=6.0 <999", diff --git a/src/AbstractEnum.php b/src/AbstractEnum.php index 3c89b5e..435ea33 100644 --- a/src/AbstractEnum.php +++ b/src/AbstractEnum.php @@ -2,7 +2,8 @@ namespace Greg0ire\Enum; -use Doctrine\Common\Inflector\Inflector; +use Doctrine\Inflector\Inflector; +use Doctrine\Inflector\InflectorFactory; use Greg0ire\Enum\Exception\InvalidEnumName; use Greg0ire\Enum\Exception\InvalidEnumValue; @@ -19,6 +20,11 @@ abstract class AbstractEnum private static $constCache = []; + /** + * @var Inflector + */ + private static $inflector; + /** * Uses reflection to find the constants defined in the class and cache * them in a local property for performance, before returning them. @@ -98,7 +104,11 @@ final public static function getClassPrefixedKeys( ?string $namespaceSeparator = null ): array { $namespaceSeparator = $namespaceSeparator ?: static::$defaultNamespaceSeparator; - $classKey = str_replace('\\', $namespaceSeparator, Inflector::tableize(static::class)); + $classKey = str_replace( + '\\', + $namespaceSeparator, + self::inflector()->tableize(static::class) + ); $keys = static::getKeys(function ($key) use ($namespaceSeparator, $classKey) { return $classKey.$namespaceSeparator.$key; @@ -111,6 +121,15 @@ final public static function getClassPrefixedKeys( return $keys; } + private static function inflector(): Inflector + { + if (!isset(self::$inflector)) { + self::$inflector = InflectorFactory::create()->build(); + } + + return self::$inflector; + } + /** * Checks whether a constant with this name is defined. */