Skip to content

Commit 43bddc1

Browse files
derrabusdunglas
andauthored
Handle deprecations from Doctrine Inflector (#3564)
* Handle deprecations from Doctrine Inflector. * Move Inflector to Util Co-authored-by: Kévin Dunglas <[email protected]>
1 parent 2502e50 commit 43bddc1

File tree

8 files changed

+61
-7
lines changed

8 files changed

+61
-7
lines changed

src/Annotation/AttributesHydratorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Core\Annotation;
1515

1616
use ApiPlatform\Core\Exception\InvalidArgumentException;
17-
use Doctrine\Common\Inflector\Inflector;
17+
use ApiPlatform\Core\Util\Inflector;
1818

1919
/**
2020
* Hydrates attributes from annotation's parameters.

src/Bridge/Elasticsearch/Metadata/Document/Factory/CatDocumentMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use ApiPlatform\Core\Bridge\Elasticsearch\Exception\IndexNotFoundException;
1717
use ApiPlatform\Core\Bridge\Elasticsearch\Metadata\Document\DocumentMetadata;
1818
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
19-
use Doctrine\Common\Inflector\Inflector;
19+
use ApiPlatform\Core\Util\Inflector;
2020
use Elasticsearch\Client;
2121
use Elasticsearch\Common\Exceptions\Missing404Exception;
2222

src/Bridge/Symfony/Routing/RouteNameGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use ApiPlatform\Core\Api\OperationType;
1717
use ApiPlatform\Core\Api\OperationTypeDeprecationHelper;
1818
use ApiPlatform\Core\Exception\InvalidArgumentException;
19-
use Doctrine\Common\Inflector\Inflector;
19+
use ApiPlatform\Core\Util\Inflector;
2020

2121
/**
2222
* Generates the Symfony route name associated with an operation name and a resource short name.

src/GraphQl/Type/FieldsBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2222
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
2323
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
24-
use Doctrine\Common\Inflector\Inflector;
24+
use ApiPlatform\Core\Util\Inflector;
2525
use GraphQL\Type\Definition\InputObjectType;
2626
use GraphQL\Type\Definition\NullableType;
2727
use GraphQL\Type\Definition\Type as GraphQLType;

src/Operation/DashPathSegmentNameGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace ApiPlatform\Core\Operation;
1515

16-
use Doctrine\Common\Inflector\Inflector;
16+
use ApiPlatform\Core\Util\Inflector;
1717

1818
/**
1919
* Generate a path name with a dash separator according to a string and whether it's a collection or not.

src/Operation/UnderscorePathSegmentNameGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace ApiPlatform\Core\Operation;
1515

16-
use Doctrine\Common\Inflector\Inflector;
16+
use ApiPlatform\Core\Util\Inflector;
1717

1818
/**
1919
* Generate a path name with an underscore separator according to a string and whether it's a collection or not.

src/Util/AnnotationFilterExtractorTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use ApiPlatform\Core\Annotation\ApiFilter;
1717
use Doctrine\Common\Annotations\Reader;
18-
use Doctrine\Common\Inflector\Inflector;
1918

2019
/**
2120
* Generates a service id for a generic filter.

src/Util/Inflector.php

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

0 commit comments

Comments
 (0)