isDevMode = $isDevMode === null ? WP_DEBUG : $isDevMode; $this->annotationReaderProvider = $annotationReaderProvider; } public function createConfiguration() { $configuration = new Configuration(); $configuration->setNamingStrategy(new UnderscoreNamingStrategy(\CASE_LOWER, true)); $this->configureMetadata($configuration); $this->configureProxies($configuration); $this->configureCache($configuration); return $configuration; } private function configureMetadata(Configuration $configuration) { $configuration->setClassMetadataFactoryName(TablePrefixMetadataFactory::class); // annotation reader exists only in dev environment, on production cache is pre-generated $annotationReader = $this->annotationReaderProvider->getAnnotationReader(); $isReadOnly = !$annotationReader; $metadataStorage = new PSRMetadataCache(self::METADATA_DIR, $isReadOnly); $configuration->setMetadataCache($metadataStorage); if ($isReadOnly) { $configuration->setMetadataDriverImpl(new CacheOnlyMappingDriver($metadataStorage)); } else { $configuration->setMetadataDriverImpl(new AnnotationDriver($annotationReader, [self::ENTITY_DIR])); } } private function configureProxies(Configuration $configuration) { $configuration->setProxyDir(self::PROXY_DIR); $configuration->setProxyNamespace(self::PROXY_NAMESPACE); $configuration->setAutoGenerateProxyClasses( $this->isDevMode ? AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS : AbstractProxyFactory::AUTOGENERATE_NEVER ); } private function configureCache(Configuration $configuration) { $cache = new ArrayCache(); $configuration->setQueryCacheImpl($cache); $configuration->setResultCacheImpl($cache); } }