diff --git a/composer.json b/composer.json index 8ad2d42..b46c6ce 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "cweagans/composer-patches": "^1.7", "doctrine/orm": "2.15.*", "fastybird/metadata-library": "dev-main", - "fastybird/simple-auth": "^0.12", + "fastybird/simple-auth": "^0.13", "nette/bootstrap": "^3.1", "nette/application": "^3.1", "nette/di": "^3.0", diff --git a/src/Subscribers/EntityDiscriminator.php b/src/Subscribers/EntityDiscriminator.php index 8c3dbf5..b660d6b 100644 --- a/src/Subscribers/EntityDiscriminator.php +++ b/src/Subscribers/EntityDiscriminator.php @@ -21,8 +21,12 @@ use FastyBird\Library\Application\Exceptions; use ReflectionClass; use function array_keys; +use function end; +use function explode; use function in_array; use function sprintf; +use function str_contains; +use function strtolower; /** * @package FastyBird:ApplicationLibrary! @@ -82,6 +86,10 @@ public function loadClassMetadata(ORM\Event\LoadClassMetadataEventArgs $event): } } + if (!in_array($classReflection->name, $extendedDiscriminatorMap, true)) { + $extendedDiscriminatorMap[$this->getShortName($classReflection->name)] = $classReflection->name; + } + foreach ($extendedDiscriminatorMap as $name => $classString) { $metadata->addDiscriminatorMapClass($name, $classString); } @@ -166,4 +174,15 @@ private function ensureDiscriminatorIsUnique(string $discriminator, ReflectionCl } } + private function getShortName(string $className): string + { + if (!str_contains($className, '\\')) { + return strtolower($className); + } + + $parts = explode('\\', $className); + + return strtolower(end($parts)); + } + }