|
|
|
@@ -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; |
|
|
|
} |