Skip to content

Commit e44da36

Browse files
authored
Merge pull request #27 from intaro/orm3
doctrine/orm 3 compability
2 parents bbc405b + 8615a12 commit e44da36

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Command/IndexUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private function dropIndexes(array $indexesNames, array $customIndexes, Extended
9696
private function dropIndex(ExtendedPlatform $platform, string $indexName): void
9797
{
9898
if ($this->input->getOption(self::DUMP_SQL_OPTION)) {
99-
$this->output->writeln($platform->getDropIndexSQL($indexName) . ';');
99+
$this->output->writeln($platform->getDropIndexSQL($indexName, '') . ';');
100100

101101
return;
102102
}

Metadata/Reader.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Doctrine\ORM\EntityManagerInterface;
66
use Doctrine\ORM\Mapping\ClassMetadata;
7-
use Doctrine\ORM\Mapping\ClassMetadataInfo;
87
use Intaro\CustomIndexBundle\DTO\CustomIndex;
98

109
/**
@@ -85,7 +84,7 @@ private function collect(
8584
*/
8685
private function getTableNameFromMetadata(ClassMetadata $metadata, ClassMetadata $parentMetadata): string
8786
{
88-
if (ClassMetadataInfo::INHERITANCE_TYPE_JOINED === $metadata->inheritanceType) {
87+
if (ClassMetadata::INHERITANCE_TYPE_JOINED === $metadata->inheritanceType) {
8988
return $parentMetadata->getTableName();
9089
}
9190

@@ -99,15 +98,15 @@ private function getTableNameFromMetadata(ClassMetadata $metadata, ClassMetadata
9998
*/
10099
private function getCustomIndexesAttributes(ClassMetadata $meta): array
101100
{
102-
return $meta->getReflectionClass()->getAttributes(Attribute\CustomIndex::class);
101+
return $this->getMetaReflectionClass($meta)->getAttributes(Attribute\CustomIndex::class);
103102
}
104103

105104
/**
106105
* @param ClassMetadata<T> $meta
107106
*/
108107
private function isAbstract(ClassMetadata $meta): bool
109108
{
110-
return $meta->getReflectionClass()->isAbstract();
109+
return $this->getMetaReflectionClass($meta)->isAbstract();
111110
}
112111

113112
/**
@@ -135,7 +134,7 @@ private function getAbstractClassesInfo(array $metadata): array
135134
*/
136135
private function searchParentsWithIndex(ClassMetadata $meta, array $abstractClasses): array
137136
{
138-
$reflectionClass = $meta->getReflectionClass();
137+
$reflectionClass = $this->getMetaReflectionClass($meta);
139138
$parentMeta = [];
140139
foreach ($abstractClasses as $entityName => $entityMeta) {
141140
if ($reflectionClass->isSubclassOf($entityName)) {
@@ -145,4 +144,19 @@ private function searchParentsWithIndex(ClassMetadata $meta, array $abstractClas
145144

146145
return $parentMeta;
147146
}
147+
148+
/**
149+
* @param ClassMetadata<T> $meta
150+
*
151+
* @return \ReflectionClass<T>
152+
*/
153+
private function getMetaReflectionClass(ClassMetadata $meta): \ReflectionClass
154+
{
155+
$reflectionClass = $meta->getReflectionClass();
156+
if (null === $reflectionClass) {
157+
throw new \RuntimeException('Reflection class is not found for ' . $meta->getName());
158+
}
159+
160+
return $reflectionClass;
161+
}
148162
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}],
1212
"require": {
1313
"php": "^8.1",
14-
"doctrine/orm": "^2.2.3",
14+
"doctrine/orm": "^2.2.3 || ^3.0",
1515
"symfony/config": "^5.0 || ^6.0",
1616
"symfony/console": "^5.0 || ^6.0",
1717
"symfony/dependency-injection": "^5.0 || ^6.0",

0 commit comments

Comments
 (0)