|
|
@@ -61,6 +61,7 @@ class SchemaSnippetsMaker
|
|
|
$class = $this->makeSnippetEntityClass($entity);
|
|
|
|
|
|
$methods = [];
|
|
|
+ $collections = [];
|
|
|
|
|
|
$expectedFields = [];
|
|
|
if (!is_array($differences)) {
|
|
|
@@ -82,9 +83,19 @@ class SchemaSnippetsMaker
|
|
|
|
|
|
$class->addMember($prop);
|
|
|
|
|
|
+ if ($prop->getType() === Collection::class) {
|
|
|
+ $collections[] = $prop;
|
|
|
+ }
|
|
|
+
|
|
|
$methods = [...$methods, ...$this->makeMethodsSnippetForProp($prop)];
|
|
|
}
|
|
|
|
|
|
+ if ($collections) {
|
|
|
+ $class->addMember(
|
|
|
+ $this->makeSnippetConstructor($collections)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
foreach ($methods as $method) {
|
|
|
$class->addMember($method);
|
|
|
}
|
|
|
@@ -266,7 +277,15 @@ class SchemaSnippetsMaker
|
|
|
*/
|
|
|
protected function getNamespaceValue(string $entity): string
|
|
|
{
|
|
|
- return $this->entityUtils->getNamespaceFromName($entity) ?? ('App\\Entity\\' . $entity);
|
|
|
+ try {
|
|
|
+ $fullQualifiedName = str_contains($entity, "\\") ?
|
|
|
+ $entity :
|
|
|
+ $this->entityUtils->getFullNameFromEntityName($entity);
|
|
|
+
|
|
|
+ return $this->entityUtils->getNamespaceFromName($fullQualifiedName);
|
|
|
+ } catch (\LogicException) {
|
|
|
+ return 'App\\Entity';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -439,6 +458,22 @@ class SchemaSnippetsMaker
|
|
|
return $prop;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Make the '__construct' method with collections initialization
|
|
|
+ * @param array $collections
|
|
|
+ * @return Method
|
|
|
+ */
|
|
|
+ protected function makeSnippetConstructor(array $collections): Method {
|
|
|
+ $constructor = new Method('__construct');
|
|
|
+ $constructor->setPublic();
|
|
|
+
|
|
|
+ foreach ($collections as $collection) {
|
|
|
+ $constructor->addBody('$this->' . $collection->getName() . ' = new ArrayCollection();');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $constructor;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Make a 'getter' method for the given property
|
|
|
*
|