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