Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctrine/orm 3 compability #27

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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