-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle deprecations from Doctrine Inflector (#3564)
* Handle deprecations from Doctrine Inflector. * Move Inflector to Util Co-authored-by: Kévin Dunglas <[email protected]>
- Loading branch information
Showing
8 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Util; | ||
|
||
use Doctrine\Common\Inflector\Inflector as LegacyInflector; | ||
use Doctrine\Inflector\Inflector as InflectorObject; | ||
use Doctrine\Inflector\InflectorFactory; | ||
|
||
/** | ||
* Facade for Doctrine Inflector. | ||
* | ||
* This class allows us to maintain compatibility with Doctrine Inflector 1.3 and 2.0 at the same time. | ||
* | ||
* @internal | ||
*/ | ||
final class Inflector | ||
{ | ||
/** | ||
* @var InflectorObject | ||
*/ | ||
private static $instance; | ||
|
||
private static function getInstance(): InflectorObject | ||
{ | ||
return self::$instance | ||
?? self::$instance = InflectorFactory::create()->build(); | ||
} | ||
|
||
/** | ||
* @see LegacyInflector::tableize() | ||
*/ | ||
public static function tableize(string $word): string | ||
{ | ||
return class_exists(InflectorFactory::class) ? self::getInstance()->tableize($word) : LegacyInflector::tableize($word); | ||
} | ||
|
||
/** | ||
* @see LegacyInflector::pluralize() | ||
*/ | ||
public static function pluralize(string $word): string | ||
{ | ||
return class_exists(InflectorFactory::class) ? self::getInstance()->pluralize($word) : LegacyInflector::pluralize($word); | ||
} | ||
} |