12
12
namespace Symfony \Bundle \MakerBundle \Maker ;
13
13
14
14
use Doctrine \Bundle \DoctrineBundle \DoctrineBundle ;
15
- use Doctrine \Common \Inflector \Inflector as LegacyInflector ;
16
- use Doctrine \Inflector \InflectorFactory ;
17
15
use Sensio \Bundle \FrameworkExtraBundle \Configuration \ParamConverter ;
18
16
use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
19
17
use Symfony \Bundle \MakerBundle \ConsoleStyle ;
32
30
use Symfony \Component \Form \AbstractType ;
33
31
use Symfony \Component \Routing \Annotation \Route ;
34
32
use Symfony \Component \Security \Csrf \CsrfTokenManager ;
33
+ use Symfony \Component \String \Inflector \EnglishInflector ;
35
34
use Symfony \Component \Validator \Validation ;
36
35
37
36
/**
@@ -52,9 +51,7 @@ public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $fo
52
51
$ this ->doctrineHelper = $ doctrineHelper ;
53
52
$ this ->formTypeRenderer = $ formTypeRenderer ;
54
53
55
- if (class_exists (InflectorFactory::class)) {
56
- $ this ->inflector = InflectorFactory::create ()->build ();
57
- }
54
+ $ this ->inflector = new EnglishInflector ();
58
55
}
59
56
60
57
public static function getCommandName (): string
@@ -124,7 +121,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
124
121
$ repositoryVars = [
125
122
'repository_full_class_name ' => $ repositoryClassDetails ->getFullName (),
126
123
'repository_class_name ' => $ repositoryClassDetails ->getShortName (),
127
- 'repository_var ' => lcfirst ($ this ->singularize ($ repositoryClassDetails ->getShortName ())),
124
+ 'repository_var ' => lcfirst ($ this ->inflector -> singularize ($ repositoryClassDetails ->getShortName ())[ 0 ] ),
128
125
];
129
126
}
130
127
@@ -144,8 +141,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
144
141
++$ iter ;
145
142
} while (class_exists ($ formClassDetails ->getFullName ()));
146
143
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 ] );
149
146
150
147
$ entityTwigVarPlural = Str::asTwigVariable ($ entityVarPlural );
151
148
$ entityTwigVarSingular = Str::asTwigVariable ($ entityVarSingular );
@@ -273,22 +270,4 @@ public function configureDependencies(DependencyBuilder $dependencies)
273
270
'annotations '
274
271
);
275
272
}
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
- }
294
273
}
0 commit comments