Daniel há 2 anos
ascendente
cometimento
3fed94ecbf
5 ficheiros alterados com 6 adições e 113 eliminações
  1. +1
    -0
      .gitignore
  2. +2
    -0
      httpdocs/config/packages/doctrine.yaml
  3. +3
    -3
      httpdocs/src/Entity/EntCustomerContact.php
  4. +0
    -4
      httpdocs/src/Entity/EntUser.php
  5. +0
    -106
      httpdocs/src/Entity/convertAnnotations.php

+ 1
- 0
.gitignore Ver ficheiro

@@ -0,0 +1 @@
/.idea

+ 2
- 0
httpdocs/config/packages/doctrine.yaml Ver ficheiro

@@ -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)


+ 3
- 3
httpdocs/src/Entity/EntCustomerContact.php Ver ficheiro

@@ -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');


+ 0
- 4
httpdocs/src/Entity/EntUser.php Ver ficheiro

@@ -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
{


+ 0
- 106
httpdocs/src/Entity/convertAnnotations.php Ver ficheiro

@@ -1,106 +0,0 @@
<?php
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\DocParser;
use Doctrine\Common\Annotations\IndexedReader;
use Doctrine\Common\Annotations\PhpParser;
use Doctrine\ORM\Mapping\Column;
use Doctrine\DBAL\Types\Types;

// Lade die Klassen, die du konvertieren möchtest
$entityDir = './';

// Initialisiere den AnnotationReader
$annotationReader = new AnnotationReader();

// Erzeuge den DocParser mit der gewünschten PHP-Parser-Klasse
$phpParser = new PhpParser();
$docParser = new DocParser($phpParser);
$docParser->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;
}

Carregando…
Cancelar
Guardar