prefix = Env::$dbPrefix; $this->setProxyClassNameResolver(new ProxyClassNameResolver()); } /** * @return ClassMetadata */ public function getMetadataFor($className) { $classMetadata = parent::getMetadataFor($className); if (isset($this->prefixedMap[$classMetadata->getName()])) { return $classMetadata; } // prefix tables only after they are saved to cache so the prefix does not get included in cache // (getMetadataFor can call itself recursively but it saves to cache only after the recursive calls) $cacheKey = $this->getCacheKey($classMetadata->getName()); $isCached = ($cache = $this->getCache()) ? $cache->hasItem($cacheKey) : false; if ($classMetadata instanceof ClassMetadata && $isCached) { $this->addPrefix($classMetadata); $this->prefixedMap[$classMetadata->getName()] = true; } return $classMetadata; } /** * @param ClassMetadata $classMetadata */ public function addPrefix(ClassMetadata $classMetadata) { if (!$classMetadata->isInheritanceTypeSingleTable() || $classMetadata->getName() === $classMetadata->rootEntityName) { $classMetadata->setPrimaryTable([ 'name' => $this->prefix . $classMetadata->getTableName(), ]); } foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && $mapping['isOwningSide']) { $mappedTableName = $mapping['joinTable']['name']; $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName; } } } }