<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing namespace MailPoet\Doctrine; if (!defined('ABSPATH')) exit; use MailPoet\Doctrine\Annotations\AnnotationReaderProvider; use MailPoetVendor\Doctrine\Common\Proxy\AbstractProxyFactory; use MailPoetVendor\Doctrine\ORM\Configuration; use MailPoetVendor\Doctrine\ORM\Mapping\Driver\AnnotationDriver; use MailPoetVendor\Doctrine\ORM\Mapping\UnderscoreNamingStrategy; class ConfigurationFactory { const ENTITY_DIR = __DIR__ . '/../Entities'; const METADATA_DIR = __DIR__ . '/../../generated/doctrine-metadata'; const PROXY_DIR = __DIR__ . '/../../generated/doctrine-proxies'; const PROXY_NAMESPACE = 'MailPoetDoctrineProxies'; /** @var bool */ private $isDevMode; /** @var AnnotationReaderProvider */ private $annotationReaderProvider; public function __construct( AnnotationReaderProvider $annotationReaderProvider, $isDevMode = null ) { $this->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); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Annotations | Folder | 0755 |
|
|
EntityTraits | Folder | 0755 |
|
|
EventListeners | Folder | 0755 |
|
|
Middlewares | Folder | 0755 |
|
|
Types | Folder | 0755 |
|
|
Validator | Folder | 0755 |
|
|
WPDB | Folder | 0755 |
|
|
ArrayCache.php | File | 2.01 KB | 0644 |
|
CacheOnlyMappingDriver.php | File | 1.67 KB | 0644 |
|
ConfigurationFactory.php | File | 2.7 KB | 0644 |
|
ConnectionFactory.php | File | 1.84 KB | 0644 |
|
EntityManagerFactory.php | File | 3.94 KB | 0644 |
|
MetadataCache.php | File | 2.69 KB | 0644 |
|
PSRArrayCache.php | File | 1.76 KB | 0644 |
|
PSRCacheInvalidArgumentException.php | File | 319 B | 0644 |
|
PSRCacheItem.php | File | 1.09 KB | 0644 |
|
PSRMetadataCache.php | File | 2.34 KB | 0644 |
|
ProxyClassNameResolver.php | File | 1.11 KB | 0644 |
|
Repository.php | File | 4.46 KB | 0644 |
|
TablePrefixMetadataFactory.php | File | 3.23 KB | 0644 |
|
index.php | File | 6 B | 0644 |
|