Skip to content

Commit

Permalink
Merge 3.x into master (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude authored Apr 26, 2024
2 parents 91f83d0 + b2289ee commit ccca471
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Doctrine/PolyglotListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ private function loadTranslationMetadataForClass($className, EntityManager $em):

$metadataFactory = $em->getMetadataFactory();
$cache = $em->getConfiguration()->getMetadataCache();
$cacheKey = $this->getCacheKey($className);

if ($cache?->hasItem($className.self::CACHE_SALT)) {
$item = $cache->getItem($className.self::CACHE_SALT);
if ($cache?->hasItem($cacheKey)) {
$item = $cache->getItem($cacheKey);
$data = $item->get();
if (null === $data) {
$this->translatedClasses[$className] = null;
Expand All @@ -163,11 +164,22 @@ private function loadTranslationMetadataForClass($className, EntityManager $em):

// Save if cache driver available
if ($cache) {
$item = $cache->getItem($className.self::CACHE_SALT);
$item = $cache->getItem($cacheKey);
$item->set($meta?->sleep());
$cache->save($item);
}

return $meta;
}

// this is taken from \Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory::escapeClassName
private function getCacheKey(string $class): string
{
if (str_contains($class, '@')) {
// anonymous class: replace all PSR6-reserved characters
return str_replace(["\0", '\\', '/', '@', ':', '{', '}', '(', ')'], '.', $class).self::CACHE_SALT;
}

return str_replace('\\', '.', $class).self::CACHE_SALT;
}
}

0 comments on commit ccca471

Please sign in to comment.