1212namespace Symfony \Bundle \MakerBundle \Doctrine ;
1313
1414use Doctrine \ORM \Mapping \ClassMetadata ;
15+ use Doctrine \ORM \Mapping \EmbeddedClassMapping ;
1516use Doctrine \ORM \Mapping \MappingException ;
1617use Doctrine \Persistence \Mapping \MappingException as PersistenceMappingException ;
1718use Symfony \Bundle \MakerBundle \Exception \RuntimeCommandException ;
1819use Symfony \Bundle \MakerBundle \FileManager ;
1920use Symfony \Bundle \MakerBundle \Generator ;
21+ use Symfony \Bundle \MakerBundle \Util \ClassSource \Model \ClassProperty ;
2022use Symfony \Bundle \MakerBundle \Util \ClassSourceManipulator ;
2123
2224/**
@@ -75,7 +77,8 @@ public function regenerateEntities(string $classOrNamespace): void
7577 continue ;
7678 }
7779
78- $ className = $ mapping ['class ' ];
80+ /** @legacy - Remove conditional when ORM 2.x is no longer supported. */
81+ $ className = ($ mapping instanceof EmbeddedClassMapping) ? $ mapping ->class : $ mapping ['class ' ];
7982
8083 $ embeddedClasses [$ fieldName ] = $ this ->getPathOfClass ($ className );
8184
@@ -93,7 +96,10 @@ public function regenerateEntities(string $classOrNamespace): void
9396 if (str_contains ($ fieldName , '. ' )) {
9497 [$ fieldName , $ embeddedFiledName ] = explode ('. ' , $ fieldName );
9598
96- $ operations [$ embeddedClasses [$ fieldName ]]->addEntityField ($ embeddedFiledName , $ mapping );
99+ $ property = ClassProperty::createFromObject ($ mapping );
100+ $ property ->propertyName = $ embeddedFiledName ;
101+
102+ $ operations [$ embeddedClasses [$ fieldName ]]->addEntityField ($ property );
97103
98104 continue ;
99105 }
@@ -102,71 +108,29 @@ public function regenerateEntities(string $classOrNamespace): void
102108 continue ;
103109 }
104110
105- $ manipulator ->addEntityField ($ fieldName , $ mapping );
111+ $ manipulator ->addEntityField (ClassProperty:: createFromObject ( $ mapping) );
106112 }
107113
108- $ getIsNullable = function (array $ mapping ) {
109- if (!isset ($ mapping ['joinColumns ' ][0 ]['nullable ' ])) {
110- // the default for relationships IS nullable
111- return true ;
112- }
113-
114- return $ mapping ['joinColumns ' ][0 ]['nullable ' ];
115- };
116-
117114 foreach ($ classMetadata ->associationMappings as $ fieldName => $ mapping ) {
118115 if (!\in_array ($ fieldName , $ mappedFields )) {
119116 continue ;
120117 }
121118
122119 switch ($ mapping ['type ' ]) {
123120 case ClassMetadata::MANY_TO_ONE :
124- $ relation = (new RelationManyToOne (
125- propertyName: $ mapping ['fieldName ' ],
126- targetClassName: $ mapping ['targetEntity ' ],
127- targetPropertyName: $ mapping ['inversedBy ' ],
128- mapInverseRelation: null !== $ mapping ['inversedBy ' ],
129- isOwning: true ,
130- isNullable: $ getIsNullable ($ mapping ),
131- ));
132-
133- $ manipulator ->addManyToOneRelation ($ relation );
121+ $ manipulator ->addManyToOneRelation (RelationManyToOne::createFromObject ($ mapping ));
134122
135123 break ;
136124 case ClassMetadata::ONE_TO_MANY :
137- $ relation = (new RelationOneToMany (
138- propertyName: $ mapping ['fieldName ' ],
139- targetClassName: $ mapping ['targetEntity ' ],
140- targetPropertyName: $ mapping ['mappedBy ' ],
141- orphanRemoval: $ mapping ['orphanRemoval ' ],
142- ));
143-
144- $ manipulator ->addOneToManyRelation ($ relation );
125+ $ manipulator ->addOneToManyRelation (RelationOneToMany::createFromObject ($ mapping ));
145126
146127 break ;
147128 case ClassMetadata::MANY_TO_MANY :
148- $ relation = (new RelationManyToMany (
149- propertyName: $ mapping ['fieldName ' ],
150- targetClassName: $ mapping ['targetEntity ' ],
151- targetPropertyName: $ mapping ['mappedBy ' ],
152- mapInverseRelation: $ mapping ['isOwningSide ' ] ? (null !== $ mapping ['inversedBy ' ]) : true ,
153- isOwning: $ mapping ['isOwningSide ' ],
154- ));
155-
156- $ manipulator ->addManyToManyRelation ($ relation );
129+ $ manipulator ->addManyToManyRelation (RelationManyToMany::createFromObject ($ mapping ));
157130
158131 break ;
159132 case ClassMetadata::ONE_TO_ONE :
160- $ relation = (new RelationOneToOne (
161- propertyName: $ mapping ['fieldName ' ],
162- targetClassName: $ mapping ['targetEntity ' ],
163- targetPropertyName: $ mapping ['isOwningSide ' ] ? $ mapping ['inversedBy ' ] : $ mapping ['mappedBy ' ],
164- mapInverseRelation: $ mapping ['isOwningSide ' ] ? (null !== $ mapping ['inversedBy ' ]) : true ,
165- isOwning: $ mapping ['isOwningSide ' ],
166- isNullable: $ getIsNullable ($ mapping ),
167- ));
168-
169- $ manipulator ->addOneToOneRelation ($ relation );
133+ $ manipulator ->addOneToOneRelation (RelationOneToOne::createFromObject ($ mapping ));
170134
171135 break ;
172136 default :
0 commit comments