Skip to content

Commit

Permalink
Merge pull request #27 from intaro/orm3
Browse files Browse the repository at this point in the history
doctrine/orm 3 compability
  • Loading branch information
muxx authored Oct 21, 2024
2 parents bbc405b + 8615a12 commit e44da36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Command/IndexUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function dropIndexes(array $indexesNames, array $customIndexes, Extended
private function dropIndex(ExtendedPlatform $platform, string $indexName): void
{
if ($this->input->getOption(self::DUMP_SQL_OPTION)) {
$this->output->writeln($platform->getDropIndexSQL($indexName) . ';');
$this->output->writeln($platform->getDropIndexSQL($indexName, '') . ';');

return;
}
Expand Down
24 changes: 19 additions & 5 deletions Metadata/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Intaro\CustomIndexBundle\DTO\CustomIndex;

/**
Expand Down Expand Up @@ -85,7 +84,7 @@ private function collect(
*/
private function getTableNameFromMetadata(ClassMetadata $metadata, ClassMetadata $parentMetadata): string
{
if (ClassMetadataInfo::INHERITANCE_TYPE_JOINED === $metadata->inheritanceType) {
if (ClassMetadata::INHERITANCE_TYPE_JOINED === $metadata->inheritanceType) {
return $parentMetadata->getTableName();
}

Expand All @@ -99,15 +98,15 @@ private function getTableNameFromMetadata(ClassMetadata $metadata, ClassMetadata
*/
private function getCustomIndexesAttributes(ClassMetadata $meta): array
{
return $meta->getReflectionClass()->getAttributes(Attribute\CustomIndex::class);
return $this->getMetaReflectionClass($meta)->getAttributes(Attribute\CustomIndex::class);
}

/**
* @param ClassMetadata<T> $meta
*/
private function isAbstract(ClassMetadata $meta): bool
{
return $meta->getReflectionClass()->isAbstract();
return $this->getMetaReflectionClass($meta)->isAbstract();
}

/**
Expand Down Expand Up @@ -135,7 +134,7 @@ private function getAbstractClassesInfo(array $metadata): array
*/
private function searchParentsWithIndex(ClassMetadata $meta, array $abstractClasses): array
{
$reflectionClass = $meta->getReflectionClass();
$reflectionClass = $this->getMetaReflectionClass($meta);
$parentMeta = [];
foreach ($abstractClasses as $entityName => $entityMeta) {
if ($reflectionClass->isSubclassOf($entityName)) {
Expand All @@ -145,4 +144,19 @@ private function searchParentsWithIndex(ClassMetadata $meta, array $abstractClas

return $parentMeta;
}

/**
* @param ClassMetadata<T> $meta
*
* @return \ReflectionClass<T>
*/
private function getMetaReflectionClass(ClassMetadata $meta): \ReflectionClass
{
$reflectionClass = $meta->getReflectionClass();
if (null === $reflectionClass) {
throw new \RuntimeException('Reflection class is not found for ' . $meta->getName());
}

return $reflectionClass;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}],
"require": {
"php": "^8.1",
"doctrine/orm": "^2.2.3",
"doctrine/orm": "^2.2.3 || ^3.0",
"symfony/config": "^5.0 || ^6.0",
"symfony/console": "^5.0 || ^6.0",
"symfony/dependency-injection": "^5.0 || ^6.0",
Expand Down

0 comments on commit e44da36

Please sign in to comment.