Skip to content

Commit

Permalink
change of doctrine inflector by symfony string and inflector
Browse files Browse the repository at this point in the history
  • Loading branch information
flug committed Jun 18, 2020
1 parent dabbcb6 commit 4f90041
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/Annotation/AttributesHydratorTrait.php
Expand Up @@ -14,7 +14,7 @@
namespace ApiPlatform\Core\Annotation;

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

/**
* Hydrates attributes from annotation's parameters.
Expand Down
Expand Up @@ -15,8 +15,8 @@

use ApiPlatform\Core\Bridge\Elasticsearch\Exception\IndexNotFoundException;
use ApiPlatform\Core\Bridge\Elasticsearch\Metadata\Document\DocumentMetadata;
use ApiPlatform\Core\Inflector\Inflector;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
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
Expand Up @@ -16,7 +16,7 @@
use ApiPlatform\Core\Api\OperationType;
use ApiPlatform\Core\Api\OperationTypeDeprecationHelper;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Util\Inflector;
use ApiPlatform\Core\Inflector\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
Expand Up @@ -17,11 +17,11 @@
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\GraphQl\Resolver\Factory\ResolverFactoryInterface;
use ApiPlatform\Core\GraphQl\Type\Definition\TypeInterface;
use ApiPlatform\Core\Inflector\Inflector;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use ApiPlatform\Core\Util\Inflector;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\NullableType;
use GraphQL\Type\Definition\Type as GraphQLType;
Expand Down
50 changes: 50 additions & 0 deletions src/Inflector/Inflector.php
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\Inflector;

use Doctrine\Common\Inflector\Inflector as LegacyInflector;
use Symfony\Component\Inflector\Inflector as SymfonyInflector;

/**
* @internal
*
* @deprecated removed in version 3.0
*/
final class Inflector
{
public static function tableize(string $word): string
{
if (\function_exists('\Symfony\Component\String\u')) {
return (string) \Symfony\Component\String\u($word)->snake();
}
@trigger_error('This method is deprecated use symfony/string',
E_USER_DEPRECATED);

return LegacyInflector::tableize($word);
}

public static function pluralize(string $singular): string
{
if (class_exists(SymfonyInflector::class)) {
$singularization = SymfonyInflector::singularize($singular);
$pluralization = SymfonyInflector::pluralize(\is_array($singularization) ? end($singularization) : $singularization);

return \is_array($pluralization) ? end($pluralization) : $pluralization;
}
@trigger_error('This method is deprecated use symfony/string',
E_USER_DEPRECATED);

return LegacyInflector::pluralize($singular);
}
}
2 changes: 1 addition & 1 deletion src/Operation/DashPathSegmentNameGenerator.php
Expand Up @@ -13,7 +13,7 @@

namespace ApiPlatform\Core\Operation;

use ApiPlatform\Core\Util\Inflector;
use ApiPlatform\Core\Inflector\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
Expand Up @@ -13,7 +13,7 @@

namespace ApiPlatform\Core\Operation;

use ApiPlatform\Core\Util\Inflector;
use ApiPlatform\Core\Inflector\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: 1 addition & 0 deletions src/Util/AnnotationFilterExtractorTrait.php
Expand Up @@ -14,6 +14,7 @@
namespace ApiPlatform\Core\Util;

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

/**
Expand Down
55 changes: 0 additions & 55 deletions src/Util/Inflector.php

This file was deleted.

0 comments on commit 4f90041

Please sign in to comment.