Cache
9 months ago
Decorator
9 months ago
Event
9 months ago
Exception
9 months ago
Id
9 months ago
Internal
9 months ago
Mapping
9 months ago
Persisters
8 months ago
Proxy
9 months ago
Query
9 months ago
Repository
9 months ago
Tools
9 months ago
Utility
9 months ago
AbstractQuery.php
9 months ago
Cache.php
9 months ago
Configuration.php
9 months ago
EntityManager.php
9 months ago
EntityManagerInterface.php
9 months ago
EntityNotFoundException.php
9 months ago
EntityRepository.php
9 months ago
Events.php
9 months ago
LazyCriteriaCollection.php
9 months ago
NativeQuery.php
9 months ago
NoResultException.php
9 months ago
NonUniqueResultException.php
9 months ago
ORMException.php
9 months ago
ORMInvalidArgumentException.php
9 months ago
ORMSetup.php
9 months ago
OptimisticLockException.php
9 months ago
PersistentCollection.php
9 months ago
PessimisticLockException.php
9 months ago
Query.php
9 months ago
QueryBuilder.php
9 months ago
TransactionRequiredException.php
9 months ago
UnexpectedResultException.php
9 months ago
UnitOfWork.php
9 months ago
Version.php
9 months ago
index.php
9 months ago
ORMSetup.php
110 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\Common\Annotations\AnnotationReader; |
| 6 | use MailPoetVendor\Doctrine\Common\Annotations\PsrCachedReader; |
| 7 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 8 | use MailPoetVendor\Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
| 9 | use MailPoetVendor\Doctrine\ORM\Mapping\Driver\AttributeDriver; |
| 10 | use MailPoetVendor\Doctrine\ORM\Mapping\Driver\XmlDriver; |
| 11 | use MailPoetVendor\Doctrine\ORM\Mapping\Driver\YamlDriver; |
| 12 | use LogicException; |
| 13 | use MailPoetVendor\Psr\Cache\CacheItemPoolInterface; |
| 14 | use Redis; |
| 15 | use RuntimeException; |
| 16 | use MailPoetVendor\Symfony\Component\Cache\Adapter\ApcuAdapter; |
| 17 | use MailPoetVendor\Symfony\Component\Cache\Adapter\ArrayAdapter; |
| 18 | use MailPoetVendor\Symfony\Component\Cache\Adapter\MemcachedAdapter; |
| 19 | use MailPoetVendor\Symfony\Component\Cache\Adapter\RedisAdapter; |
| 20 | use function apcu_enabled; |
| 21 | use function class_exists; |
| 22 | use function extension_loaded; |
| 23 | use function md5; |
| 24 | use function sys_get_temp_dir; |
| 25 | final class ORMSetup |
| 26 | { |
| 27 | public static function createAnnotationMetadataConfiguration(array $paths, bool $isDevMode = \false, ?string $proxyDir = null, ?CacheItemPoolInterface $cache = null) : Configuration |
| 28 | { |
| 29 | Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/orm/issues/10098', '%s is deprecated and will be removed in Doctrine ORM 3.0', __METHOD__); |
| 30 | $config = self::createConfiguration($isDevMode, $proxyDir, $cache); |
| 31 | $config->setMetadataDriverImpl(self::createDefaultAnnotationDriver($paths)); |
| 32 | return $config; |
| 33 | } |
| 34 | public static function createDefaultAnnotationDriver(array $paths = [], ?CacheItemPoolInterface $cache = null, bool $reportFieldsWhereDeclared = \false) : AnnotationDriver |
| 35 | { |
| 36 | Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/orm/issues/10098', '%s is deprecated and will be removed in Doctrine ORM 3.0', __METHOD__); |
| 37 | if (!class_exists(AnnotationReader::class)) { |
| 38 | throw new LogicException('The annotation metadata driver cannot be enabled because the "doctrine/annotations" library' . ' is not installed. Please run "composer require doctrine/annotations" or choose a different' . ' metadata driver.'); |
| 39 | } |
| 40 | $reader = new AnnotationReader(); |
| 41 | if ($cache === null && class_exists(ArrayAdapter::class)) { |
| 42 | $cache = new ArrayAdapter(); |
| 43 | } |
| 44 | if ($cache !== null) { |
| 45 | $reader = new PsrCachedReader($reader, $cache); |
| 46 | } |
| 47 | return new AnnotationDriver($reader, $paths, $reportFieldsWhereDeclared); |
| 48 | } |
| 49 | public static function createAttributeMetadataConfiguration(array $paths, bool $isDevMode = \false, ?string $proxyDir = null, ?CacheItemPoolInterface $cache = null, bool $reportFieldsWhereDeclared = \false) : Configuration |
| 50 | { |
| 51 | $config = self::createConfiguration($isDevMode, $proxyDir, $cache); |
| 52 | $config->setMetadataDriverImpl(new AttributeDriver($paths, $reportFieldsWhereDeclared)); |
| 53 | return $config; |
| 54 | } |
| 55 | public static function createXMLMetadataConfiguration(array $paths, bool $isDevMode = \false, ?string $proxyDir = null, ?CacheItemPoolInterface $cache = null, bool $isXsdValidationEnabled = \false) : Configuration |
| 56 | { |
| 57 | $config = self::createConfiguration($isDevMode, $proxyDir, $cache); |
| 58 | $config->setMetadataDriverImpl(new XmlDriver($paths, XmlDriver::DEFAULT_FILE_EXTENSION, $isXsdValidationEnabled)); |
| 59 | return $config; |
| 60 | } |
| 61 | public static function createYAMLMetadataConfiguration(array $paths, bool $isDevMode = \false, ?string $proxyDir = null, ?CacheItemPoolInterface $cache = null) : Configuration |
| 62 | { |
| 63 | Deprecation::trigger('doctrine/orm', 'https://github.com/doctrine/orm/issues/8465', 'YAML mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to attribute or XML driver.'); |
| 64 | $config = self::createConfiguration($isDevMode, $proxyDir, $cache); |
| 65 | $config->setMetadataDriverImpl(new YamlDriver($paths)); |
| 66 | return $config; |
| 67 | } |
| 68 | public static function createConfiguration(bool $isDevMode = \false, ?string $proxyDir = null, ?CacheItemPoolInterface $cache = null) : Configuration |
| 69 | { |
| 70 | $proxyDir = $proxyDir ?: sys_get_temp_dir(); |
| 71 | $cache = self::createCacheInstance($isDevMode, $proxyDir, $cache); |
| 72 | $config = new Configuration(); |
| 73 | $config->setMetadataCache($cache); |
| 74 | $config->setQueryCache($cache); |
| 75 | $config->setResultCache($cache); |
| 76 | $config->setProxyDir($proxyDir); |
| 77 | $config->setProxyNamespace('DoctrineProxies'); |
| 78 | $config->setAutoGenerateProxyClasses($isDevMode); |
| 79 | return $config; |
| 80 | } |
| 81 | private static function createCacheInstance(bool $isDevMode, string $proxyDir, ?CacheItemPoolInterface $cache) : CacheItemPoolInterface |
| 82 | { |
| 83 | if ($cache !== null) { |
| 84 | return $cache; |
| 85 | } |
| 86 | if (!class_exists(ArrayAdapter::class)) { |
| 87 | throw new RuntimeException('The Doctrine setup tool cannot configure caches without symfony/cache.' . ' Please add symfony/cache as explicit dependency or pass your own cache implementation.'); |
| 88 | } |
| 89 | if ($isDevMode) { |
| 90 | return new ArrayAdapter(); |
| 91 | } |
| 92 | $namespace = 'dc2_' . md5($proxyDir); |
| 93 | if (extension_loaded('apcu') && apcu_enabled()) { |
| 94 | return new ApcuAdapter($namespace); |
| 95 | } |
| 96 | if (MemcachedAdapter::isSupported()) { |
| 97 | return new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://127.0.0.1'), $namespace); |
| 98 | } |
| 99 | if (extension_loaded('redis')) { |
| 100 | $redis = new Redis(); |
| 101 | $redis->connect('127.0.0.1'); |
| 102 | return new RedisAdapter($redis, $namespace); |
| 103 | } |
| 104 | return new ArrayAdapter(); |
| 105 | } |
| 106 | private function __construct() |
| 107 | { |
| 108 | } |
| 109 | } |
| 110 |