Skip to content

Commit dac9462

Browse files
committed
use EnglishInflector instead of inflector
1 parent f6d49b2 commit dac9462

File tree

2 files changed

+10
-49
lines changed

2 files changed

+10
-49
lines changed

src/Maker/MakeCrud.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
15-
use Doctrine\Common\Inflector\Inflector as LegacyInflector;
16-
use Doctrine\Inflector\InflectorFactory;
1715
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
1816
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1917
use Symfony\Bundle\MakerBundle\ConsoleStyle;
@@ -32,6 +30,7 @@
3230
use Symfony\Component\Form\AbstractType;
3331
use Symfony\Component\Routing\Annotation\Route;
3432
use Symfony\Component\Security\Csrf\CsrfTokenManager;
33+
use Symfony\Component\String\Inflector\EnglishInflector;
3534
use Symfony\Component\Validator\Validation;
3635

3736
/**
@@ -52,9 +51,7 @@ public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $fo
5251
$this->doctrineHelper = $doctrineHelper;
5352
$this->formTypeRenderer = $formTypeRenderer;
5453

55-
if (class_exists(InflectorFactory::class)) {
56-
$this->inflector = InflectorFactory::create()->build();
57-
}
54+
$this->inflector = new EnglishInflector();
5855
}
5956

6057
public static function getCommandName(): string
@@ -124,7 +121,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
124121
$repositoryVars = [
125122
'repository_full_class_name' => $repositoryClassDetails->getFullName(),
126123
'repository_class_name' => $repositoryClassDetails->getShortName(),
127-
'repository_var' => lcfirst($this->singularize($repositoryClassDetails->getShortName())),
124+
'repository_var' => lcfirst($this->inflector->singularize($repositoryClassDetails->getShortName())[0]),
128125
];
129126
}
130127

@@ -144,8 +141,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
144141
++$iter;
145142
} while (class_exists($formClassDetails->getFullName()));
146143

147-
$entityVarPlural = lcfirst($this->pluralize($entityClassDetails->getShortName()));
148-
$entityVarSingular = lcfirst($this->singularize($entityClassDetails->getShortName()));
144+
$entityVarPlural = lcfirst($this->inflector->pluralize($entityClassDetails->getShortName())[0]);
145+
$entityVarSingular = lcfirst($this->inflector->singularize($entityClassDetails->getShortName())[0]);
149146

150147
$entityTwigVarPlural = Str::asTwigVariable($entityVarPlural);
151148
$entityTwigVarSingular = Str::asTwigVariable($entityVarSingular);
@@ -273,22 +270,4 @@ public function configureDependencies(DependencyBuilder $dependencies)
273270
'annotations'
274271
);
275272
}
276-
277-
private function pluralize(string $word): string
278-
{
279-
if (null !== $this->inflector) {
280-
return $this->inflector->pluralize($word);
281-
}
282-
283-
return LegacyInflector::pluralize($word);
284-
}
285-
286-
private function singularize(string $word): string
287-
{
288-
if (null !== $this->inflector) {
289-
return $this->inflector->singularize($word);
290-
}
291-
292-
return LegacyInflector::singularize($word);
293-
}
294273
}

src/Str.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,15 @@
1111

1212
namespace Symfony\Bundle\MakerBundle;
1313

14-
use Doctrine\Common\Inflector\Inflector as LegacyInflector;
15-
use Doctrine\Inflector\Inflector;
16-
use Doctrine\Inflector\InflectorFactory;
1714
use Symfony\Component\DependencyInjection\Container;
15+
use Symfony\Component\String\Inflector\EnglishInflector;
1816

1917
/**
2018
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
2119
* @author Ryan Weaver <weaverryan@gmail.com>
2220
*/
2321
final class Str
2422
{
25-
/** @var Inflector|null */
26-
private static $inflector;
27-
2823
/**
2924
* Looks for suffixes in strings in a case-insensitive way.
3025
*/
@@ -220,28 +215,15 @@ public static function asHumanWords(string $variableName): string
220215

221216
private static function pluralize(string $word): string
222217
{
223-
if (class_exists(Inflector::class)) {
224-
return static::getInflector()->pluralize($word);
225-
}
218+
$result = (new EnglishInflector())->pluralize($word);
226219

227-
return LegacyInflector::pluralize($word);
220+
return $result[0];
228221
}
229222

230223
private static function singularize(string $word): string
231224
{
232-
if (class_exists(Inflector::class)) {
233-
return static::getInflector()->singularize($word);
234-
}
235-
236-
return LegacyInflector::singularize($word);
237-
}
238-
239-
private static function getInflector(): Inflector
240-
{
241-
if (null === static::$inflector) {
242-
static::$inflector = InflectorFactory::create()->build();
243-
}
225+
$result = (new EnglishInflector())->singularize($word);
244226

245-
return static::$inflector;
227+
return $result[0];
246228
}
247229
}

0 commit comments

Comments
 (0)