Skip to content

Handle deprecations from Doctrine Inflector #3564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}