From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vendor/doctrine/orm/src/ORMSetup.php | 127 +++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 vendor/doctrine/orm/src/ORMSetup.php (limited to 'vendor/doctrine/orm/src/ORMSetup.php') diff --git a/vendor/doctrine/orm/src/ORMSetup.php b/vendor/doctrine/orm/src/ORMSetup.php new file mode 100644 index 0000000..7354c71 --- /dev/null +++ b/vendor/doctrine/orm/src/ORMSetup.php @@ -0,0 +1,127 @@ +setMetadataDriverImpl(new AttributeDriver($paths)); + + return $config; + } + + /** + * Creates a configuration with an XML metadata driver. + * + * @param string[] $paths + */ + public static function createXMLMetadataConfiguration( + array $paths, + bool $isDevMode = false, + string|null $proxyDir = null, + CacheItemPoolInterface|null $cache = null, + bool $isXsdValidationEnabled = true, + ): Configuration { + $config = self::createConfiguration($isDevMode, $proxyDir, $cache); + $config->setMetadataDriverImpl(new XmlDriver($paths, XmlDriver::DEFAULT_FILE_EXTENSION, $isXsdValidationEnabled)); + + return $config; + } + + /** + * Creates a configuration without a metadata driver. + */ + public static function createConfiguration( + bool $isDevMode = false, + string|null $proxyDir = null, + CacheItemPoolInterface|null $cache = null, + ): Configuration { + $proxyDir = $proxyDir ?: sys_get_temp_dir(); + + $cache = self::createCacheInstance($isDevMode, $proxyDir, $cache); + + $config = new Configuration(); + + $config->setMetadataCache($cache); + $config->setQueryCache($cache); + $config->setResultCache($cache); + $config->setProxyDir($proxyDir); + $config->setProxyNamespace('DoctrineProxies'); + $config->setAutoGenerateProxyClasses($isDevMode); + + return $config; + } + + private static function createCacheInstance( + bool $isDevMode, + string $proxyDir, + CacheItemPoolInterface|null $cache, + ): CacheItemPoolInterface { + if ($cache !== null) { + return $cache; + } + + if (! class_exists(ArrayAdapter::class)) { + 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.', + ); + } + + if ($isDevMode) { + return new ArrayAdapter(); + } + + $namespace = 'dc2_' . md5($proxyDir); + + if (extension_loaded('apcu') && apcu_enabled()) { + return new ApcuAdapter($namespace); + } + + if (MemcachedAdapter::isSupported()) { + return new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://127.0.0.1'), $namespace); + } + + if (extension_loaded('redis')) { + $redis = new Redis(); + $redis->connect('127.0.0.1'); + + return new RedisAdapter($redis, $namespace); + } + + return new ArrayAdapter(); + } + + private function __construct() + { + } +} -- cgit v1.2.3