Skip to content
Closed
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"require": {
"php": ">=7.1",
"doctrine/inflector": "^1.0",
"doctrine/inflector": "^1.4 || ^2.0",
"fig/link-util": "^1.0",
"psr/cache": "^1.0",
"psr/container": "^1.0",
Expand Down
6 changes: 4 additions & 2 deletions 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 Doctrine\Inflector\InflectorFactory;

/**
* Hydrates attributes from annotation's parameters.
Expand All @@ -36,6 +36,8 @@ trait AttributesHydratorTrait
*/
private function hydrateAttributes(array $values): void
{
$inflector = InflectorFactory::create()->build();

if (isset($values['attributes'])) {
$this->attributes = $values['attributes'];
unset($values['attributes']);
Expand Down Expand Up @@ -67,7 +69,7 @@ private function hydrateAttributes(array $values): void
$this->attributes = [];
}

$this->attributes += [Inflector::tableize($key) => $value];
$this->attributes += [$inflector->tableize($key) => $value];
}
}
}
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 Doctrine\Inflector\InflectorFactory;
use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\Missing404Exception;

Expand Down Expand Up @@ -48,6 +48,7 @@ public function __construct(Client $client, ResourceMetadataFactoryInterface $re
public function create(string $resourceClass): DocumentMetadata
{
$documentMetadata = null;
$inflector = InflectorFactory::create()->build();

if ($this->decorated) {
try {
Expand All @@ -64,7 +65,7 @@ public function create(string $resourceClass): DocumentMetadata
return $this->handleNotFound($documentMetadata, $resourceClass);
}

$index = Inflector::tableize($resourceShortName);
$index = $inflector->tableize($resourceShortName);

try {
$this->client->cat()->indices(['index' => $index]);
Expand Down
8 changes: 5 additions & 3 deletions src/Bridge/Symfony/Routing/RouteNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
use ApiPlatform\Core\Api\OperationType;
use ApiPlatform\Core\Api\OperationTypeDeprecationHelper;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;

/**
* Generates the Symfony route name associated with an operation name and a resource short name.
Expand Down Expand Up @@ -64,8 +65,9 @@ public static function generate(string $operationName, string $resourceShortName
*/
public static function inflector(string $name, bool $pluralize = true): string
{
$name = Inflector::tableize($name);
$inflector = InflectorFactory::create()->build();
$name = $inflector->tableize($name);

return $pluralize ? Inflector::pluralize($name) : $name;
return $pluralize ? $inflector->pluralize($name) : $name;
}
}
6 changes: 4 additions & 2 deletions 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 Doctrine\Inflector\InflectorFactory;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\NullableType;
use GraphQL\Type\Definition\Type as GraphQLType;
Expand Down Expand Up @@ -113,6 +113,8 @@ public function getItemQueryFields(string $resourceClass, ResourceMetadata $reso
*/
public function getCollectionQueryFields(string $resourceClass, ResourceMetadata $resourceMetadata, string $queryName, array $configuration): array
{
$inflector = InflectorFactory::create()->build();

$shortName = $resourceMetadata->getShortName();
$fieldName = lcfirst('collection_query' === $queryName ? $shortName : $queryName.$shortName);
$description = $resourceMetadata->getGraphqlAttribute($queryName, 'description');
Expand All @@ -122,7 +124,7 @@ public function getCollectionQueryFields(string $resourceClass, ResourceMetadata
$args = $this->resolveResourceArgs($configuration['args'] ?? [], $queryName, $shortName);
$configuration['args'] = $args ?: $configuration['args'] ?? $fieldConfiguration['args'];

return [Inflector::pluralize($fieldName) => array_merge($fieldConfiguration, $configuration)];
return [$inflector->pluralize($fieldName) => array_merge($fieldConfiguration, $configuration)];
}

return [];
Expand Down
6 changes: 4 additions & 2 deletions 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 Doctrine\Inflector\InflectorFactory;

/**
* Generate a path name with a dash separator according to a string and whether it's a collection or not.
Expand All @@ -27,7 +27,9 @@ final class DashPathSegmentNameGenerator implements PathSegmentNameGeneratorInte
*/
public function getSegmentName(string $name, bool $collection = true): string
{
return $collection ? $this->dashize(Inflector::pluralize($name)) : $this->dashize($name);
$inflector = InflectorFactory::create()->build();

return $collection ? $this->dashize($inflector->pluralize($name)) : $this->dashize($name);
}

private function dashize(string $string): string
Expand Down
7 changes: 4 additions & 3 deletions 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 Doctrine\Inflector\InflectorFactory;

/**
* Generate a path name with an underscore separator according to a string and whether it's a collection or not.
Expand All @@ -27,8 +27,9 @@ final class UnderscorePathSegmentNameGenerator implements PathSegmentNameGenerat
*/
public function getSegmentName(string $name, bool $collection = true): string
{
$name = Inflector::tableize($name);
$inflector = InflectorFactory::create()->build();
$name = $inflector->tableize($name);

return $collection ? Inflector::pluralize($name) : $name;
return $collection ? $inflector->pluralize($name) : $name;
}
}
5 changes: 3 additions & 2 deletions src/Util/AnnotationFilterExtractorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

/**
* Generates a service id for a generic filter.
Expand Down Expand Up @@ -136,7 +136,8 @@ private function readFilterAnnotations(\ReflectionClass $reflectionClass, Reader
private function generateFilterId(\ReflectionClass $reflectionClass, string $filterClass, string $filterId = null): string
{
$suffix = null !== $filterId ? '_'.$filterId : $filterId;
$inflector = InflectorFactory::create()->build();

return 'annotated_'.Inflector::tableize(str_replace('\\', '', $reflectionClass->getName().(new \ReflectionClass($filterClass))->getName().$suffix));
return 'annotated_'.$inflector->tableize(str_replace('\\', '', $reflectionClass->getName().(new \ReflectionClass($filterClass))->getName().$suffix));
}
}