Skip to content

Commit f0c8d84

Browse files
committed
use EnglishInflector instead of inflector
1 parent 185994c commit f0c8d84

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/Maker/MakeCrud.php

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

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
15-
use Doctrine\Inflector\InflectorFactory;
1615
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
1716
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1817
use Symfony\Bundle\MakerBundle\ConsoleStyle;
@@ -31,6 +30,7 @@
3130
use Symfony\Component\Form\AbstractType;
3231
use Symfony\Component\Routing\Annotation\Route;
3332
use Symfony\Component\Security\Csrf\CsrfTokenManager;
33+
use Symfony\Component\String\Inflector\EnglishInflector;
3434
use Symfony\Component\Validator\Validation;
3535

3636
/**
@@ -50,7 +50,8 @@ public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $fo
5050
{
5151
$this->doctrineHelper = $doctrineHelper;
5252
$this->formTypeRenderer = $formTypeRenderer;
53-
$this->inflector = InflectorFactory::create()->build();
53+
54+
$this->inflector = new EnglishInflector();
5455
}
5556

5657
public static function getCommandName(): string
@@ -120,7 +121,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
120121
$repositoryVars = [
121122
'repository_full_class_name' => $repositoryClassDetails->getFullName(),
122123
'repository_class_name' => $repositoryClassDetails->getShortName(),
123-
'repository_var' => lcfirst($this->inflector->singularize($repositoryClassDetails->getShortName())),
124+
'repository_var' => lcfirst($this->inflector->singularize($repositoryClassDetails->getShortName())[0]),
124125
];
125126
}
126127

@@ -140,8 +141,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
140141
++$iter;
141142
} while (class_exists($formClassDetails->getFullName()));
142143

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

146147
$entityTwigVarPlural = Str::asTwigVariable($entityVarPlural);
147148
$entityTwigVarSingular = Str::asTwigVariable($entityVarSingular);

src/Str.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111

1212
namespace Symfony\Bundle\MakerBundle;
1313

14-
use Doctrine\Inflector\Inflector;
15-
use Doctrine\Inflector\InflectorFactory;
1614
use Symfony\Component\DependencyInjection\Container;
15+
use Symfony\Component\String\Inflector\EnglishInflector;
1716

1817
/**
1918
* @author Javier Eguiluz <[email protected]>
2019
* @author Ryan Weaver <[email protected]>
2120
*/
2221
final class Str
2322
{
24-
/** @var Inflector|null */
25-
private static $inflector;
26-
2723
/**
2824
* Looks for suffixes in strings in a case-insensitive way.
2925
*/
@@ -219,20 +215,15 @@ public static function asHumanWords(string $variableName): string
219215

220216
private static function pluralize(string $word): string
221217
{
222-
return static::getInflector()->pluralize($word);
223-
}
218+
$result = (new EnglishInflector())->pluralize($word);
224219

225-
private static function singularize(string $word): string
226-
{
227-
return static::getInflector()->singularize($word);
220+
return $result[0];
228221
}
229222

230-
private static function getInflector(): Inflector
223+
private static function singularize(string $word): string
231224
{
232-
if (null === static::$inflector) {
233-
static::$inflector = InflectorFactory::create()->build();
234-
}
225+
$result = (new EnglishInflector())->singularize($word);
235226

236-
return static::$inflector;
227+
return $result[0];
237228
}
238229
}

0 commit comments

Comments
 (0)