فهرست منبع

minor fixes on SchemaSnippetsMaker service

Olivier Massot 1 سال پیش
والد
کامیت
17299cdd4f
1فایلهای تغییر یافته به همراه14 افزوده شده و 3 حذف شده
  1. 14 3
      src/Service/Doctrine/SchemaValidation/SchemaSnippetsMaker.php

+ 14 - 3
src/Service/Doctrine/SchemaValidation/SchemaSnippetsMaker.php

@@ -16,6 +16,7 @@ use Doctrine\ORM\Mapping\ManyToMany;
 use Doctrine\ORM\Mapping\ManyToOne;
 use Doctrine\ORM\Mapping\OneToMany;
 use Doctrine\ORM\Mapping\OneToOne;
+use Nette\InvalidStateException;
 use Nette\PhpGenerator\Attribute;
 use Nette\PhpGenerator\ClassType;
 use Nette\PhpGenerator\Method;
@@ -98,7 +99,12 @@ class SchemaSnippetsMaker
                 }
             }
 
-            $namespace->add($class);
+            try {
+                $namespace->add($class);
+            } catch (InvalidStateException $e) {
+                var_dump($e->getMessage());
+                continue;
+            }
 
             $file->addNamespace($namespace);
 
@@ -337,10 +343,14 @@ class SchemaSnippetsMaker
      */
     protected function makeSnippetEntitySimpleProp(string $name, string $type): Property
     {
+        if ($name === 'id') {
+            return $this->makeIdPropertySnippet();
+        }
+
         $php_type = $this->getPhpTypeFromDoctrineType($type);
 
         $prop = new Property($name);
-        $prop->setPrivate();
+        $prop->setProtected();
         $prop->setType($php_type);
 
         if ($type === 'text') {
@@ -371,6 +381,7 @@ class SchemaSnippetsMaker
     protected function makeSnippetEntityCollectionProp(string $name, array $type): Property
     {
         $prop = new Property($name);
+        $prop->setProtected();
         $prop->setType('Collection');
 
         if (
@@ -408,7 +419,7 @@ class SchemaSnippetsMaker
             $options['cascade'] = ['persist'];
         }
 
-        if (isset($type['orphanRemoval'])) {
+        if (isset($type['orphanRemoval']) && ($type['type'] === ClassMetadataInfo::ONE_TO_MANY || $type['type'] === ClassMetadataInfo::MANY_TO_MANY)) {
             $options['orphanRemoval'] = $type['orphanRemoval'];
         }