@@ -221,7 +221,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
221
221
$ identityClassNameDetails = $ this ->generateIdentity ($ modelName , $ input , $ io , $ generator );
222
222
$ this ->generateEntityMappings ($ modelClassNameDetails , $ input , $ io , $ generator );
223
223
$ this ->generateEntity ($ modelClassNameDetails , $ input , $ generator );
224
- $ this ->generateRepository ($ modelClassNameDetails , $ identityClassNameDetails , $ input , $ generator );
224
+ $ this ->generateRepository ($ generator , $ input , $ modelClassNameDetails , $ identityClassNameDetails );
225
225
226
226
$ this ->writeSuccessMessage ($ io );
227
227
}
@@ -423,9 +423,9 @@ private function generateEntityMappings(
423
423
[
424
424
'model_class ' => $ modelClassNameDetails ->getFullName (),
425
425
'has_identity ' => $ hasIdentity ,
426
- 'type_name ' => $ this ->templateVariables ['type_name ' ],
426
+ 'type_name ' => $ hasIdentity ?? $ this ->templateVariables ['type_name ' ],
427
427
'table_name ' => $ tableName ,
428
- 'identity_column_name ' => $ this ->templateVariables ['identity_type ' ],
428
+ 'identity_column_name ' => $ hasIdentity ?? $ this ->templateVariables ['identity_type ' ],
429
429
],
430
430
);
431
431
} catch (YamlManipulationFailedException $ e ) {
@@ -470,17 +470,16 @@ private function generateEntity(
470
470
/**
471
471
* Generate model repository
472
472
*
473
- * @param ClassNameDetails $modelClassNameDetails
474
- * @param ClassNameDetails $identityClassNameDetails
475
- * @param InputInterface $input
476
473
* @param Generator $generator
477
- * @throws \Exception
474
+ * @param InputInterface $input
475
+ * @param ClassNameDetails $modelClassNameDetails
476
+ * @param ?ClassNameDetails $identityClassNameDetails
478
477
*/
479
478
private function generateRepository (
480
- ClassNameDetails $ modelClassNameDetails ,
481
- ClassNameDetails $ identityClassNameDetails ,
479
+ Generator $ generator ,
482
480
InputInterface $ input ,
483
- Generator $ generator
481
+ ClassNameDetails $ modelClassNameDetails ,
482
+ ?ClassNameDetails $ identityClassNameDetails ,
484
483
): void {
485
484
$ interfaceNameDetails = $ generator ->createClassNameDetails (
486
485
$ input ->getArgument ('name ' ),
@@ -489,10 +488,10 @@ private function generateRepository(
489
488
);
490
489
491
490
$ this ->generateRepositoryInterface (
491
+ $ generator ,
492
492
$ interfaceNameDetails ,
493
493
$ modelClassNameDetails ,
494
494
$ identityClassNameDetails ,
495
- $ generator
496
495
);
497
496
498
497
$ implementationNameDetails = $ generator ->createClassNameDetails (
@@ -503,17 +502,17 @@ private function generateRepository(
503
502
504
503
$ interfaceClassName = $ interfaceNameDetails ->getShortName () . 'Interface ' ;
505
504
$ templateVars = [
506
- 'use_statements ' => new UseStatementGenerator ([
505
+ 'use_statements ' => new UseStatementGenerator (array_filter ( [
507
506
$ modelClassNameDetails ->getFullName (),
508
- $ identityClassNameDetails ->getFullName (),
507
+ $ identityClassNameDetails? ->getFullName(),
509
508
ManagerRegistry::class,
510
509
QueryBuilder::class,
511
510
[ OrmRepository::class => 'OrmRepository ' ],
512
511
[ $ interfaceNameDetails ->getFullName () => $ interfaceClassName ],
513
- ]),
512
+ ])) ,
514
513
'interface_class_name ' => $ interfaceClassName ,
515
514
'model_class_name ' => $ modelClassNameDetails ->getShortName (),
516
- 'identity_class_name ' => $ identityClassNameDetails ->getShortName ()
515
+ 'identity_class_name ' => $ identityClassNameDetails? ->getShortName()
517
516
];
518
517
519
518
$ templatePath = __DIR__ .'/../Resources/skeleton/model/Repository.tpl.php ' ;
@@ -529,26 +528,26 @@ private function generateRepository(
529
528
/**
530
529
* Generate model repository
531
530
*
532
- * @param ClassNameDetails $classNameDetails
533
- * @param ClassNameDetails $entityClassNameDetails
534
- * @param ClassNameDetails $identityClassNameDetails
535
531
* @param Generator $generator
532
+ * @param ClassNameDetails $classNameDetails
533
+ * @param ClassNameDetails $modelClassNameDetails
534
+ * @param ?ClassNameDetails $identityClassNameDetails
536
535
* @throws \Exception
537
536
*/
538
537
private function generateRepositoryInterface (
538
+ Generator $ generator ,
539
539
ClassNameDetails $ classNameDetails ,
540
540
ClassNameDetails $ modelClassNameDetails ,
541
- ClassNameDetails $ identityClassNameDetails ,
542
- Generator $ generator
541
+ ?ClassNameDetails $ identityClassNameDetails ,
543
542
): void {
544
543
$ templateVars = [
545
- 'use_statements ' => new UseStatementGenerator ([
544
+ 'use_statements ' => new UseStatementGenerator (array_filter ( [
546
545
$ modelClassNameDetails ->getFullName (),
547
- $ identityClassNameDetails ->getFullName (),
546
+ $ identityClassNameDetails? ->getFullName(),
548
547
Repository::class,
549
- ]),
548
+ ])) ,
550
549
'model_class_name ' => $ modelClassNameDetails ->getShortName (),
551
- 'identity_class_name ' => $ identityClassNameDetails ->getShortName ()
550
+ 'identity_class_name ' => $ identityClassNameDetails? ->getShortName()
552
551
];
553
552
554
553
$ templatePath = __DIR__ .'/../Resources/skeleton/model/RepositoryInterface.tpl.php ' ;
0 commit comments