@@ -65,9 +65,9 @@ final class ClassSourceManipulator
65
65
public function __construct (
66
66
string $ sourceCode ,
67
67
bool $ overwrite = false ,
68
- bool $ useAnnotations = true ,
68
+ bool $ useAnnotations = false ,
69
69
bool $ fluentMutators = true ,
70
- bool $ useAttributesForDoctrineMapping = false
70
+ bool $ useAttributesForDoctrineMapping = true
71
71
) {
72
72
$ this ->overwrite = $ overwrite ;
73
73
$ this ->useAnnotations = $ useAnnotations ;
@@ -124,7 +124,7 @@ public function addEntityField(string $propertyName, array $columnOptions, array
124
124
$ defaultValue = new Node \Expr \Array_ ([], ['kind ' => Node \Expr \Array_::KIND_SHORT ]);
125
125
}
126
126
127
- $ this ->addProperty (name: $ propertyName , annotationLines : $ comments , defaultValue : $ defaultValue , attributes : $ attributes );
127
+ $ this ->addProperty (name: $ propertyName , defaultValue : $ defaultValue , attributes : $ attributes , comments : $ comments );
128
128
129
129
$ this ->addGetter (
130
130
$ propertyName ,
@@ -144,27 +144,13 @@ public function addEmbeddedEntity(string $propertyName, string $className): void
144
144
{
145
145
$ typeHint = $ this ->addUseStatementIfNecessary ($ className );
146
146
147
- // $annotations = [];
148
- // $attributes = [];
149
- //
150
- // if (!$this->useAttributesForDoctrineMapping) {
151
- // $annotations = [
152
- // $this->buildAnnotationLine(
153
- // '@ORM\\Embedded',
154
- // [
155
- // 'class' => new ClassNameValue($className, $typeHint),
156
- // ]
157
- // ),
158
- // ];
159
- // } else {
160
147
$ attributes = [
161
148
$ this ->buildAttributeNode (
162
149
Embedded::class,
163
150
['class ' => new ClassNameValue ($ className , $ typeHint )],
164
151
'ORM '
165
152
),
166
153
];
167
- // }
168
154
169
155
$ this ->addProperty (name: $ propertyName , attributes: $ attributes );
170
156
@@ -355,8 +341,12 @@ public function createMethodLevelBlankLine()
355
341
/**
356
342
* @param array<Node\Attribute|Node\AttributeGroup> $attributes
357
343
*/
358
- public function addProperty (string $ name , array $ annotationLines = [], $ defaultValue = null , array $ attributes = []): void
344
+ public function addProperty (string $ name , array $ annotationLines = [], $ defaultValue = null , array $ attributes = [], array $ comments = [] ): void
359
345
{
346
+ if (!empty ($ annotationLines )) {
347
+ @trigger_deprecation ('symfony/maker-bundle ' , '0.0.0 ' , 'CSM:addProperty(annotationLines:) is going to be removed. Triggered from addProperty... ' );
348
+ }
349
+
360
350
if ($ this ->propertyExists ($ name )) {
361
351
// we never overwrite properties
362
352
return ;
@@ -368,8 +358,10 @@ public function addProperty(string $name, array $annotationLines = [], $defaultV
368
358
foreach ($ attributes as $ attribute ) {
369
359
$ newPropertyBuilder ->addAttribute ($ attribute );
370
360
}
371
- } elseif ($ annotationLines && $ this ->useAnnotations ) {
372
- $ newPropertyBuilder ->setDocComment ($ this ->createDocBlock ($ annotationLines ));
361
+ }
362
+
363
+ if ($ comments ) {
364
+ $ newPropertyBuilder ->setDocComment ($ this ->createDocBlock ($ comments ));
373
365
}
374
366
375
367
if (null !== $ defaultValue ) {
@@ -559,34 +551,16 @@ private function addSingularRelation(BaseRelation $relation): void
559
551
$ annotationOptions ['cascade ' ] = ['persist ' , 'remove ' ];
560
552
}
561
553
562
- // $annotations = [];
563
- // $attributes = [];
564
-
565
- // if (!$this->useAttributesForDoctrineMapping) {
566
- // $annotations = [
567
- // $this->buildAnnotationLine(
568
- // $relation instanceof RelationManyToOne ? '@ORM\\ManyToOne' : '@ORM\\OneToOne',
569
- // $annotationOptions
570
- // ),
571
- // ];
572
- // } else {
573
554
$ attributes = [
574
555
$ this ->buildAttributeNode (
575
556
$ relation instanceof RelationManyToOne ? ManyToOne::class : OneToOne::class,
576
557
$ annotationOptions ,
577
558
'ORM '
578
559
),
579
560
];
580
- // }
581
561
582
562
if (!$ relation ->isNullable () && $ relation ->isOwning ()) {
583
- // if (!$this->useAttributesForDoctrineMapping) {
584
- // $annotations[] = $this->buildAnnotationLine('@ORM\\JoinColumn', [
585
- // 'nullable' => false,
586
- // ]);
587
- // } else {
588
563
$ attributes [] = $ this ->buildAttributeNode (JoinColumn::class, ['nullable ' => false ], 'ORM ' );
589
- // }
590
564
}
591
565
592
566
$ this ->addProperty (name: $ relation ->getPropertyName (), attributes: $ attributes );
@@ -654,25 +628,13 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void
654
628
$ annotationOptions ['orphanRemoval ' ] = true ;
655
629
}
656
630
657
- // $annotations = [];
658
- // $attributes = [];
659
- //
660
- // if (!$this->useAttributesForDoctrineMapping) {
661
- // $annotations = [
662
- // $this->buildAnnotationLine(
663
- // $relation instanceof RelationManyToMany ? '@ORM\\ManyToMany' : '@ORM\\OneToMany',
664
- // $annotationOptions
665
- // ),
666
- // ];
667
- // } else {
668
631
$ attributes = [
669
632
$ this ->buildAttributeNode (
670
633
$ relation instanceof RelationManyToMany ? ManyToMany::class : OneToMany::class,
671
634
$ annotationOptions ,
672
635
'ORM '
673
636
),
674
637
];
675
- // }
676
638
677
639
$ this ->addProperty (name: $ relation ->getPropertyName (), attributes: $ attributes );
678
640
0 commit comments