Skip to content

Commit

Permalink
Handle deprecations from Doctrine Inflector (#3564)
Browse files Browse the repository at this point in the history
* Handle deprecations from Doctrine Inflector.

* Move Inflector to Util

Co-authored-by: Kévin Dunglas <[email protected]>
  • Loading branch information
derrabus and dunglas authored May 28, 2020
1 parent 2502e50 commit 43bddc1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Annotation/AttributesHydratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace ApiPlatform\Core\Annotation;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use Doctrine\Common\Inflector\Inflector;
use ApiPlatform\Core\Util\Inflector;

/**
* Hydrates attributes from annotation's parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use ApiPlatform\Core\Bridge\Elasticsearch\Exception\IndexNotFoundException;
use ApiPlatform\Core\Bridge\Elasticsearch\Metadata\Document\DocumentMetadata;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use Doctrine\Common\Inflector\Inflector;
use ApiPlatform\Core\Util\Inflector;
use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\Missing404Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Routing/RouteNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use ApiPlatform\Core\Api\OperationType;
use ApiPlatform\Core\Api\OperationTypeDeprecationHelper;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use Doctrine\Common\Inflector\Inflector;
use ApiPlatform\Core\Util\Inflector;

/**
* Generates the Symfony route name associated with an operation name and a resource short name.
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQl/Type/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use Doctrine\Common\Inflector\Inflector;
use ApiPlatform\Core\Util\Inflector;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\NullableType;
use GraphQL\Type\Definition\Type as GraphQLType;
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/DashPathSegmentNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace ApiPlatform\Core\Operation;

use Doctrine\Common\Inflector\Inflector;
use ApiPlatform\Core\Util\Inflector;

/**
* Generate a path name with a dash separator according to a string and whether it's a collection or not.
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/UnderscorePathSegmentNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace ApiPlatform\Core\Operation;

use Doctrine\Common\Inflector\Inflector;
use ApiPlatform\Core\Util\Inflector;

/**
* Generate a path name with an underscore separator according to a string and whether it's a collection or not.
Expand Down
1 change: 0 additions & 1 deletion src/Util/AnnotationFilterExtractorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use ApiPlatform\Core\Annotation\ApiFilter;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Inflector\Inflector;

/**
* Generates a service id for a generic filter.
Expand Down
55 changes: 55 additions & 0 deletions src/Util/Inflector.php
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);
}
}

0 comments on commit 43bddc1

Please sign in to comment.