Skip to content

Commit 993a1f6

Browse files
committed
Revert "move property attribute logic to one place"
This reverts commit c8ea64d.
1 parent f188e77 commit 993a1f6

File tree

2 files changed

+94
-26
lines changed

2 files changed

+94
-26
lines changed

src/Maker/MakeRegistrationForm.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,18 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
391391
);
392392
$userManipulator->setIo($io);
393393

394+
// $annotation = [];
395+
// $attrNode = [];
396+
//
397+
// if ($usesAttributes) {
398+
// $attrNode = [$userManipulator->buildAttributeNode('ORM\Column', ['type' => 'boolean'])];
399+
// } else {
400+
// $annotation = ['@ORM\Column(type="boolean")'];
401+
// }
402+
394403
$userManipulator->addProperty(
395404
'isVerified',
396-
['@ORM\Column(type="boolean")'], // @legacy - Remove when annotation support is dropped.
405+
['@ORM\Column(type="boolean")'],
397406
false,
398407
[$userManipulator->buildAttributeNode('ORM\Column', ['type' => 'boolean'])]
399408
);

src/Util/ClassSourceManipulator.php

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,20 @@ public function addEntityField(string $propertyName, array $columnOptions, array
9090
$typeHint = $this->getEntityTypeHint($columnOptions['type']);
9191
$nullable = $columnOptions['nullable'] ?? false;
9292
$isId = (bool) ($columnOptions['id'] ?? false);
93-
$comments[] = $this->buildAnnotationLine('@ORM\Column', $columnOptions);
93+
$attributes = [];
94+
95+
if ($this->useAttributesForDoctrineMapping) {
96+
$attributes[] = $this->buildAttributeNode('ORM\Column', $columnOptions);
97+
} else {
98+
$comments[] = $this->buildAnnotationLine('@ORM\Column', $columnOptions);
99+
}
94100

95101
$defaultValue = null;
96102
if ('array' === $typeHint) {
97103
$defaultValue = new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]);
98104
}
99105

100-
$this->addProperty(
101-
$propertyName,
102-
$comments,
103-
$defaultValue,
104-
[$this->buildAttributeNode('ORM\Column', $columnOptions)]
105-
);
106+
$this->addProperty($propertyName, $comments, $defaultValue, $attributes);
106107

107108
$this->addGetter(
108109
$propertyName,
@@ -122,12 +123,30 @@ public function addEmbeddedEntity(string $propertyName, string $className): void
122123
{
123124
$typeHint = $this->addUseStatementIfNecessary($className);
124125

125-
$this->addProperty(
126-
$propertyName,
127-
[$this->buildAnnotationLine('@ORM\\Embedded', ['class' => new ClassNameValue($className, $typeHint)])],
128-
null,
129-
[$this->buildAttributeNode('ORM\\Embedded', ['class' => new ClassNameValue($className, $typeHint)])]
130-
);
126+
$annotations = [];
127+
$attributes = [];
128+
129+
if (!$this->useAttributesForDoctrineMapping) {
130+
$annotations = [
131+
$this->buildAnnotationLine(
132+
'@ORM\\Embedded',
133+
[
134+
'class' => new ClassNameValue($className, $typeHint),
135+
]
136+
),
137+
];
138+
} else {
139+
$attributes = [
140+
$this->buildAttributeNode(
141+
'ORM\\Embedded',
142+
[
143+
'class' => new ClassNameValue($className, $typeHint),
144+
]
145+
),
146+
];
147+
}
148+
149+
$this->addProperty($propertyName, $annotations, null, $attributes);
131150

132151
// logic to avoid re-adding the same ArrayCollection line
133152
$addEmbedded = true;
@@ -326,12 +345,15 @@ public function addProperty(string $name, array $annotationLines = [], $defaultV
326345

327346
$newPropertyBuilder = (new Builder\Property($name))->makePrivate();
328347

329-
if ($attributes && $this->useAttributesForDoctrineMapping) {
348+
// if ($annotationLines && $this->useAnnotations) {
349+
// $newPropertyBuilder->setDocComment($this->createDocBlock($annotationLines));
350+
// }
351+
352+
if ($this->useAttributesForDoctrineMapping) {
330353
foreach ($attributes as $attribute) {
331354
$newPropertyBuilder->addAttribute($attribute);
332355
}
333356
} elseif ($annotationLines && $this->useAnnotations) {
334-
// @legacy - Remove when annotation support is dropped.
335357
$newPropertyBuilder->setDocComment($this->createDocBlock($annotationLines));
336358
}
337359

@@ -504,12 +526,35 @@ private function addSingularRelation(BaseRelation $relation): void
504526
$annotationOptions['cascade'] = ['persist', 'remove'];
505527
}
506528

507-
$annotations = [$this->buildAnnotationLine($relation instanceof RelationManyToOne ? '@ORM\\ManyToOne' : '@ORM\\OneToOne', $annotationOptions)];
508-
$attributes = [$this->buildAttributeNode($relation instanceof RelationManyToOne ? 'ORM\\ManyToOne' : 'ORM\\OneToOne', $annotationOptions)];
529+
$annotations = [];
530+
$attributes = [];
531+
532+
if (!$this->useAttributesForDoctrineMapping) {
533+
$annotations = [
534+
$this->buildAnnotationLine(
535+
$relation instanceof RelationManyToOne ? '@ORM\\ManyToOne' : '@ORM\\OneToOne',
536+
$annotationOptions
537+
),
538+
];
539+
} else {
540+
$attributes = [
541+
$this->buildAttributeNode(
542+
$relation instanceof RelationManyToOne ? 'ORM\\ManyToOne' : 'ORM\\OneToOne',
543+
$annotationOptions
544+
),
545+
];
546+
}
509547

510548
if (!$relation->isNullable() && $relation->isOwning()) {
511-
$annotations[] = $this->buildAnnotationLine('@ORM\\JoinColumn', ['nullable' => false]);
512-
$attributes[] = $this->buildAttributeNode('ORM\\JoinColumn', ['nullable' => false]);
549+
if (!$this->useAttributesForDoctrineMapping) {
550+
$annotations[] = $this->buildAnnotationLine('@ORM\\JoinColumn', [
551+
'nullable' => false,
552+
]);
553+
} else {
554+
$attributes[] = $this->buildAttributeNode('ORM\\JoinColumn', [
555+
'nullable' => false,
556+
]);
557+
}
513558
}
514559

515560
$this->addProperty($relation->getPropertyName(), $annotations, null, $attributes);
@@ -577,12 +622,26 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void
577622
$annotationOptions['orphanRemoval'] = true;
578623
}
579624

580-
$this->addProperty(
581-
$relation->getPropertyName(),
582-
[$this->buildAnnotationLine($relation instanceof RelationManyToMany ? '@ORM\\ManyToMany' : '@ORM\\OneToMany', $annotationOptions)],
583-
null,
584-
[$this->buildAttributeNode($relation instanceof RelationManyToMany ? 'ORM\\ManyToMany' : 'ORM\\OneToMany', $annotationOptions)]
585-
);
625+
$annotations = [];
626+
$attributes = [];
627+
628+
if (!$this->useAttributesForDoctrineMapping) {
629+
$annotations = [
630+
$this->buildAnnotationLine(
631+
$relation instanceof RelationManyToMany ? '@ORM\\ManyToMany' : '@ORM\\OneToMany',
632+
$annotationOptions
633+
),
634+
];
635+
} else {
636+
$attributes = [
637+
$this->buildAttributeNode(
638+
$relation instanceof RelationManyToMany ? 'ORM\\ManyToMany' : 'ORM\\OneToMany',
639+
$annotationOptions
640+
),
641+
];
642+
}
643+
644+
$this->addProperty($relation->getPropertyName(), $annotations, null, $attributes);
586645

587646
// logic to avoid re-adding the same ArrayCollection line
588647
$addArrayCollection = true;

0 commit comments

Comments
 (0)