vendor/api-platform/core/src/Util/Inflector.php line 45

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Core\Util;
  12. use Doctrine\Common\Inflector\Inflector as LegacyInflector;
  13. use Doctrine\Inflector\Inflector as InflectorObject;
  14. use Doctrine\Inflector\InflectorFactory;
  15. /**
  16.  * Facade for Doctrine Inflector.
  17.  *
  18.  * This class allows us to maintain compatibility with Doctrine Inflector 1.3 and 2.0 at the same time.
  19.  *
  20.  * @internal
  21.  */
  22. final class Inflector
  23. {
  24.     /**
  25.      * @var InflectorObject|null
  26.      */
  27.     private static $instance;
  28.     private static function getInstance(): InflectorObject
  29.     {
  30.         return self::$instance
  31.             ?? self::$instance InflectorFactory::create()->build();
  32.     }
  33.     /**
  34.      * @see InflectorObject::tableize()
  35.      */
  36.     public static function tableize(string $word): string
  37.     {
  38.         return class_exists(LegacyInflector::class) ? LegacyInflector::tableize($word) : self::getInstance()->tableize($word);
  39.     }
  40.     /**
  41.      * @see InflectorObject::pluralize()
  42.      */
  43.     public static function pluralize(string $word): string
  44.     {
  45.         return class_exists(LegacyInflector::class) ? LegacyInflector::pluralize($word) : self::getInstance()->pluralize($word);
  46.     }
  47. }