Skip to content

Commit 0461b33

Browse files
committed
[Twig] Remove phpType variable, add reflectionProperty variable
1 parent 5eb278e commit 0461b33

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

UPGRADE-4.0.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
## Template
88

9-
* When generating getters/setters for a field, the `types` variable passed to the Twig template no longer exists.
10-
It has been replaced by the `type` variable, which returns a `Symfony\Component\TypeInfo\Type` object or null.
11-
9+
* When generating getters/setters for a field :
10+
* The `types` variable passed to the Twig template no longer exists.
11+
It has been replaced by the `type` variable, which returns a `Symfony\Component\TypeInfo\Type` object or null.
12+
* The `phpType` variable passed to the Twig template no longer exists.
13+
It has been replaced by the `reflectionProperty` variable, which returns a `\ReflectionProperty` object.

src/EntityGenerator/EntityGenerator.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ protected function addField(GenerateEntityRequest $request, FieldMapping $fieldM
283283
$fieldName = $fieldMapping->fieldName;
284284
$type = $request->doctrineExtractor->getType($request->reflectionClass->getName(), $fieldName);
285285
$reflectionProperty = new \ReflectionProperty($request->reflectionClass->getName(), $fieldName);
286-
$phpType = $reflectionProperty->getType();
287286

288287
$blockPrefix = 'field';
289288
$enum = $fieldMapping->enumType;
@@ -300,7 +299,7 @@ protected function addField(GenerateEntityRequest $request, FieldMapping $fieldM
300299
'fieldName' => $fieldName,
301300
'variableName' => $this->buildVariableName(self::TYPE_SET, $fieldName),
302301
'type' => $type,
303-
'phpType' => $phpType,
302+
'reflectionProperty' => $reflectionProperty,
304303
'request' => $request,
305304
'fieldMapping' => $fieldMapping,
306305
'enum' => $enum,
@@ -316,7 +315,7 @@ protected function addField(GenerateEntityRequest $request, FieldMapping $fieldM
316315
'methodName' => $getMethodName,
317316
'fieldName' => $fieldName,
318317
'type' => $type,
319-
'phpType' => $phpType,
318+
'reflectionProperty' => $reflectionProperty,
320319
'request' => $request,
321320
'fieldMapping' => $fieldMapping,
322321
'enum' => $enum,
@@ -329,7 +328,8 @@ protected function addField(GenerateEntityRequest $request, FieldMapping $fieldM
329328
protected function addEmbedded(GenerateEntityRequest $request, string $fieldName, EmbeddedClassMapping $embeddedMapping): void
330329
{
331330
$targetClass = $embeddedMapping->class;
332-
$phpType = (new \ReflectionProperty($request->reflectionClass->getName(), $fieldName))->getType();
331+
$type = $request->doctrineExtractor->getType($request->reflectionClass->getName(), $fieldName);
332+
$reflectionProperty = new \ReflectionProperty($request->reflectionClass->getName(), $fieldName);
333333

334334
$targetClassAlias = $request->useStatementManipulator->addUseStatementIfNecessary($targetClass);
335335
if ($request->reflectionClass->getName() === $targetClass) {
@@ -344,7 +344,8 @@ protected function addEmbedded(GenerateEntityRequest $request, string $fieldName
344344
'variableName' => $this->buildVariableName(self::TYPE_SET, $fieldName),
345345
'targetClass' => $targetClass,
346346
'targetClassAlias' => $targetClassAlias,
347-
'phpType' => $phpType,
347+
'type' => $type,
348+
'reflectionProperty' => $reflectionProperty,
348349
'request' => $request,
349350
'embeddedMapping' => $embeddedMapping,
350351
]);
@@ -357,7 +358,8 @@ protected function addEmbedded(GenerateEntityRequest $request, string $fieldName
357358
'fieldName' => $fieldName,
358359
'targetClass' => $targetClass,
359360
'targetClassAlias' => $targetClassAlias,
360-
'phpType' => $phpType,
361+
'type' => $type,
362+
'reflectionProperty' => $reflectionProperty,
361363
'request' => $request,
362364
'embeddedMapping' => $embeddedMapping,
363365
]);
@@ -443,6 +445,8 @@ protected function addAssociation(GenerateEntityRequest $request, AssociationMap
443445
protected function addAssociationToOne(GenerateEntityRequest $request, AssociationMapping $associationMapping, string $block, ?string $foreignMethodNameSet): void
444446
{
445447
$fieldName = $associationMapping->fieldName;
448+
$type = $request->doctrineExtractor->getType($request->reflectionClass->getName(), $fieldName);
449+
$reflectionProperty = new \ReflectionProperty($request->reflectionClass->getName(), $fieldName);
446450
$targetEntity = $associationMapping->targetEntity;
447451

448452
$targetEntityAlias = $request->useStatementManipulator->addUseStatementIfNecessary($targetEntity);
@@ -459,6 +463,8 @@ protected function addAssociationToOne(GenerateEntityRequest $request, Associati
459463
'variableName' => $this->buildVariableName(self::TYPE_SET, $fieldName),
460464
'targetEntity' => $targetEntity,
461465
'targetEntityAlias' => $targetEntityAlias,
466+
'type' => $type,
467+
'reflectionProperty' => $reflectionProperty,
462468
'request' => $request,
463469
'associationMapping' => $associationMapping,
464470
]);
@@ -471,6 +477,8 @@ protected function addAssociationToOne(GenerateEntityRequest $request, Associati
471477
'fieldName' => $fieldName,
472478
'targetEntity' => $targetEntity,
473479
'targetEntityAlias' => $targetEntityAlias,
480+
'type' => $type,
481+
'reflectionProperty' => $reflectionProperty,
474482
'request' => $request,
475483
'associationMapping' => $associationMapping,
476484
]);
@@ -480,6 +488,8 @@ protected function addAssociationToOne(GenerateEntityRequest $request, Associati
480488
protected function addAssociationToMany(GenerateEntityRequest $request, AssociationMapping $associationMapping, string $block, ?string $foreignMethodNameAdd, ?string $foreignMethodNameRemove): void
481489
{
482490
$fieldName = $associationMapping->fieldName;
491+
$type = $request->doctrineExtractor->getType($request->reflectionClass->getName(), $fieldName);
492+
$reflectionProperty = new \ReflectionProperty($request->reflectionClass->getName(), $fieldName);
483493
$targetEntity = $associationMapping->targetEntity;
484494

485495
$targetEntityAlias = $request->useStatementManipulator->addUseStatementIfNecessary($targetEntity);
@@ -498,6 +508,8 @@ protected function addAssociationToMany(GenerateEntityRequest $request, Associat
498508
'variableName' => $this->buildVariableName(self::TYPE_ADD, $fieldName),
499509
'targetEntity' => $targetEntity,
500510
'targetEntityAlias' => $targetEntityAlias,
511+
'type' => $type,
512+
'reflectionProperty' => $reflectionProperty,
501513
'request' => $request,
502514
'associationMapping' => $associationMapping,
503515
'collectionAlias' => $collectionAlias,
@@ -513,6 +525,8 @@ protected function addAssociationToMany(GenerateEntityRequest $request, Associat
513525
'variableName' => $this->buildVariableName(self::TYPE_REMOVE, $fieldName),
514526
'targetEntity' => $targetEntity,
515527
'targetEntityAlias' => $targetEntityAlias,
528+
'type' => $type,
529+
'reflectionProperty' => $reflectionProperty,
516530
'request' => $request,
517531
'associationMapping' => $associationMapping,
518532
'collectionAlias' => $collectionAlias,
@@ -526,6 +540,8 @@ protected function addAssociationToMany(GenerateEntityRequest $request, Associat
526540
'fieldName' => $fieldName,
527541
'targetEntity' => $targetEntity,
528542
'targetEntityAlias' => $targetEntityAlias,
543+
'type' => $type,
544+
'reflectionProperty' => $reflectionProperty,
529545
'request' => $request,
530546
'associationMapping' => $associationMapping,
531547
'collectionAlias' => $collectionAlias,
@@ -536,6 +552,8 @@ protected function addAssociationToMany(GenerateEntityRequest $request, Associat
536552
'fieldName' => $fieldName,
537553
'targetEntity' => $targetEntity,
538554
'targetEntityAlias' => $targetEntityAlias,
555+
'type' => $type,
556+
'reflectionProperty' => $reflectionProperty,
539557
'request' => $request,
540558
'associationMapping' => $associationMapping,
541559
'collectionAlias' => $collectionAlias,

0 commit comments

Comments
 (0)