@@ -90,20 +90,19 @@ public function addEntityField(string $propertyName, array $columnOptions, array
90
90
$ typeHint = $ this ->getEntityTypeHint ($ columnOptions ['type ' ]);
91
91
$ nullable = $ columnOptions ['nullable ' ] ?? false ;
92
92
$ isId = (bool ) ($ columnOptions ['id ' ] ?? false );
93
- $ attributes = [];
94
-
95
- if ($ this ->useAttributesForDoctrineMapping ) {
96
- $ attributes [] = $ this ->buildAttributeNode ('ORM\Column ' , $ columnOptions );
97
- } else {
98
- $ comments [] = $ this ->buildAnnotationLine ('@ORM\Column ' , $ columnOptions );
99
- }
93
+ $ comments [] = $ this ->buildAnnotationLine ('@ORM\Column ' , $ columnOptions );
100
94
101
95
$ defaultValue = null ;
102
96
if ('array ' === $ typeHint ) {
103
97
$ defaultValue = new Node \Expr \Array_ ([], ['kind ' => Node \Expr \Array_::KIND_SHORT ]);
104
98
}
105
99
106
- $ this ->addProperty ($ propertyName , $ comments , $ defaultValue , $ attributes );
100
+ $ this ->addProperty (
101
+ $ propertyName ,
102
+ $ comments ,
103
+ $ defaultValue ,
104
+ [$ this ->buildAttributeNode ('ORM\Column ' , $ columnOptions )]
105
+ );
107
106
108
107
$ this ->addGetter (
109
108
$ propertyName ,
@@ -123,30 +122,12 @@ public function addEmbeddedEntity(string $propertyName, string $className): void
123
122
{
124
123
$ typeHint = $ this ->addUseStatementIfNecessary ($ className );
125
124
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 );
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
+ );
150
131
151
132
// logic to avoid re-adding the same ArrayCollection line
152
133
$ addEmbedded = true ;
@@ -345,15 +326,12 @@ public function addProperty(string $name, array $annotationLines = [], $defaultV
345
326
346
327
$ newPropertyBuilder = (new Builder \Property ($ name ))->makePrivate ();
347
328
348
- // if ($annotationLines && $this->useAnnotations) {
349
- // $newPropertyBuilder->setDocComment($this->createDocBlock($annotationLines));
350
- // }
351
-
352
- if ($ this ->useAttributesForDoctrineMapping ) {
329
+ if ($ attributes && $ this ->useAttributesForDoctrineMapping ) {
353
330
foreach ($ attributes as $ attribute ) {
354
331
$ newPropertyBuilder ->addAttribute ($ attribute );
355
332
}
356
333
} elseif ($ annotationLines && $ this ->useAnnotations ) {
334
+ // @legacy - Remove when annotation support is dropped.
357
335
$ newPropertyBuilder ->setDocComment ($ this ->createDocBlock ($ annotationLines ));
358
336
}
359
337
@@ -526,35 +504,12 @@ private function addSingularRelation(BaseRelation $relation): void
526
504
$ annotationOptions ['cascade ' ] = ['persist ' , 'remove ' ];
527
505
}
528
506
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
- }
507
+ $ annotations = [$ this ->buildAnnotationLine ($ relation instanceof RelationManyToOne ? '@ORM \\ManyToOne ' : '@ORM \\OneToOne ' , $ annotationOptions )];
508
+ $ attributes = [$ this ->buildAttributeNode ($ relation instanceof RelationManyToOne ? 'ORM \\ManyToOne ' : 'ORM \\OneToOne ' , $ annotationOptions )];
547
509
548
510
if (!$ relation ->isNullable () && $ relation ->isOwning ()) {
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
- }
511
+ $ annotations [] = $ this ->buildAnnotationLine ('@ORM \\JoinColumn ' , ['nullable ' => false ]);
512
+ $ attributes [] = $ this ->buildAttributeNode ('ORM \\JoinColumn ' , ['nullable ' => false ]);
558
513
}
559
514
560
515
$ this ->addProperty ($ relation ->getPropertyName (), $ annotations , null , $ attributes );
@@ -622,26 +577,12 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void
622
577
$ annotationOptions ['orphanRemoval ' ] = true ;
623
578
}
624
579
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 );
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
+ );
645
586
646
587
// logic to avoid re-adding the same ArrayCollection line
647
588
$ addArrayCollection = true ;
0 commit comments