From 3fed94ecbfec41797995c790f2be299d12db79ea Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 May 2023 16:07:44 +0200 Subject: [PATCH] wip --- .gitignore | 1 + httpdocs/config/packages/doctrine.yaml | 2 + httpdocs/src/Entity/EntCustomerContact.php | 6 +- httpdocs/src/Entity/EntUser.php | 4 - httpdocs/src/Entity/convertAnnotations.php | 106 --------------------- 5 files changed, 6 insertions(+), 113 deletions(-) create mode 100644 .gitignore delete mode 100644 httpdocs/src/Entity/convertAnnotations.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..757fee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea \ No newline at end of file diff --git a/httpdocs/config/packages/doctrine.yaml b/httpdocs/config/packages/doctrine.yaml index bdff96f..b284b6d 100644 --- a/httpdocs/config/packages/doctrine.yaml +++ b/httpdocs/config/packages/doctrine.yaml @@ -1,6 +1,8 @@ doctrine: dbal: url: '%env(resolve:DATABASE_URL)%' + mapping_types: + enum: string # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) diff --git a/httpdocs/src/Entity/EntCustomerContact.php b/httpdocs/src/Entity/EntCustomerContact.php index e4efac4..2762d7f 100644 --- a/httpdocs/src/Entity/EntCustomerContact.php +++ b/httpdocs/src/Entity/EntCustomerContact.php @@ -29,7 +29,7 @@ class EntCustomerContact implements IEntity protected $customer_id; /** - * @ORM\Column(name="gender", type="string", columnDefinition="enum('male', 'female', 'diverse')") + * @ORM\Column(name="gender", type="string", columnDefinition="ENUM('male', 'female', 'diverse')") */ protected $gender; @@ -115,12 +115,12 @@ class EntCustomerContact implements IEntity /** * EntCustomerContact constructor. - * @param ObjectManager $em + * @param EntityManagerInterface $em * @param EntCustomer $entCustomer * @param $lastName * @throws \Exception */ - public function __construct(ObjectManager $em, EntCustomer $entCustomer, $lastName) + public function __construct(EntityManagerInterface $em, EntCustomer $entCustomer, $lastName) { if (is_null($entCustomer->getId())) { throw new Exception('no id found'); diff --git a/httpdocs/src/Entity/EntUser.php b/httpdocs/src/Entity/EntUser.php index ed815bb..8173e11 100644 --- a/httpdocs/src/Entity/EntUser.php +++ b/httpdocs/src/Entity/EntUser.php @@ -11,10 +11,6 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity - * @ORM\Table(name="user") - */ #[ORM\Entity()] class EntUser implements IEntity, UserInterface { diff --git a/httpdocs/src/Entity/convertAnnotations.php b/httpdocs/src/Entity/convertAnnotations.php deleted file mode 100644 index 187d5c7..0000000 --- a/httpdocs/src/Entity/convertAnnotations.php +++ /dev/null @@ -1,106 +0,0 @@ -setIgnoreNotImportedAnnotations(true); -$docParser->setImports([ - 'orm' => 'Doctrine\ORM\Mapping', -]); - -// Initialisiere den IndexedReader mit dem AnnotationReader und DocParser -$indexedReader = new IndexedReader($annotationReader, $docParser); - -// Lade alle Entity-Klassen im Entity-Verzeichnis -$directoryIterator = new \RecursiveDirectoryIterator($entityDir); -$iterator = new \RecursiveIteratorIterator($directoryIterator); -$regexIterator = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); - -// Schleife über alle Entity-Klassen -foreach ($regexIterator as $file) { - $filePath = $file[0]; - - // Lade die Entity-Klasse und rufe die Annotationen ab - require_once $filePath; - $className = getClassNameFromFile($filePath); - $reflectionClass = new \ReflectionClass($className); - $reflectionProperties = $reflectionClass->getProperties(); - - // Konvertiere die Annotationen in die zweite Art - foreach ($reflectionProperties as $reflectionProperty) { - $annotations = $annotationReader->getPropertyAnnotations($reflectionProperty); - - foreach ($annotations as $annotation) { - if ($annotation instanceof Column) { - $type = Types::STRING; - $length = $annotation->length; - $nullable = !$annotation->nullable; - - $reflectionProperty->setAccessible(true); - $columnAnnotation = $reflectionProperty->getValue($reflectionClass); - - $columnAnnotation->type = $type; - $columnAnnotation->length = $length; - $columnAnnotation->nullable = $nullable; - - $reflectionProperty->setAccessible(false); - } - } - } -} - -/** - * Liefert den Klassennamen aus einer Datei. - * - * @param string $filePath Der Pfad zur Datei. - * - * @return string|null Der Klassenname oder null, wenn kein gültiger Klassenname gefunden wurde. - */ -function getClassNameFromFile(string $filePath): ?string -{ - $phpCode = file_get_contents($filePath); - $tokens = token_get_all($phpCode); - - $namespace = ''; - $className = ''; - $isNamespaceFound = false; - $isClassFound = false; - - foreach ($tokens as $token) { - if (is_array($token)) { - list($tokenType, $tokenValue) = $token; - - if ($tokenType === T_NAMESPACE) { - $isNamespaceFound = true; - $namespace = ''; - } elseif ($tokenType === T_CLASS) { - $isClassFound = true; - $className = ''; - } elseif ($isNamespaceFound && $tokenType === T_STRING) { - $namespace .= $tokenValue; - } elseif ($isClassFound && $tokenType === T_STRING) { - $className = $tokenValue; - break; - } - } - } - - if ($isNamespaceFound && $isClassFound && !empty($className)) { - return $namespace . '\\' . $className; - } - - return null; -}