Skip to content

Commit 3248cd0

Browse files
author
blacklizer
committed
DoctrineUtils::getClassMetadata return null if metadata not exists (instead exception)
1 parent 3ad3e89 commit 3248cd0

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

Doctrine/DoctrineUtils.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ public function getRealClass($target)
4444
*
4545
* @param object|string $entity Entity object or FQCN
4646
*
47-
* @return ClassMetadata
47+
* @return ClassMetadata|null
4848
*/
4949
public function getClassMetadata($entity)
5050
{
5151
$fqcn = $this->getRealClass($entity);
52+
5253
if (null === $entityManager = $this->doctrine->getManagerForClass($fqcn)) {
53-
throw DoctrineUtilsException::unsupportedClass($fqcn);
54+
return null;
5455
}
5556

5657
return $entityManager->getClassMetadata($fqcn);
@@ -125,4 +126,4 @@ public function dump($entity): array
125126

126127
return $dump;
127128
}
128-
}
129+
}

Exception/DoctrineUtilsException.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66

77
class DoctrineUtilsException extends RuntimeException implements SymfonyCommonExceptionInterface
88
{
9-
/**
10-
* Unsupported class exception
11-
*
12-
* @param string $fqcn FQCN
13-
*
14-
* @return $this
15-
*/
16-
public static function unsupportedClass($fqcn)
17-
{
18-
return new self("Unsupported class '$fqcn'.");
19-
}
20-
219
/**
2210
* Unsupported entity primary key
2311
*
@@ -29,4 +17,4 @@ public static function unsupportedPrimaryKey($fqcn)
2917
{
3018
return new self("Unsupported '$fqcn' primary key, supports only entities with single field primary key.");
3119
}
32-
}
20+
}

0 commit comments

Comments
 (0)