summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/ORMSetup.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/ORMSetup.php
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/ORMSetup.php')
-rw-r--r--vendor/doctrine/orm/src/ORMSetup.php127
1 files changed, 127 insertions, 0 deletions
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 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM;
6
7use Doctrine\ORM\Mapping\Driver\AttributeDriver;
8use Doctrine\ORM\Mapping\Driver\XmlDriver;
9use Psr\Cache\CacheItemPoolInterface;
10use Redis;
11use RuntimeException;
12use Symfony\Component\Cache\Adapter\ApcuAdapter;
13use Symfony\Component\Cache\Adapter\ArrayAdapter;
14use Symfony\Component\Cache\Adapter\MemcachedAdapter;
15use Symfony\Component\Cache\Adapter\RedisAdapter;
16
17use function apcu_enabled;
18use function class_exists;
19use function extension_loaded;
20use function md5;
21use function sys_get_temp_dir;
22
23final class ORMSetup
24{
25 /**
26 * Creates a configuration with an attribute metadata driver.
27 *
28 * @param string[] $paths
29 */
30 public static function createAttributeMetadataConfiguration(
31 array $paths,
32 bool $isDevMode = false,
33 string|null $proxyDir = null,
34 CacheItemPoolInterface|null $cache = null,
35 ): Configuration {
36 $config = self::createConfiguration($isDevMode, $proxyDir, $cache);
37 $config->setMetadataDriverImpl(new AttributeDriver($paths));
38
39 return $config;
40 }
41
42 /**
43 * Creates a configuration with an XML metadata driver.
44 *
45 * @param string[] $paths
46 */
47 public static function createXMLMetadataConfiguration(
48 array $paths,
49 bool $isDevMode = false,
50 string|null $proxyDir = null,
51 CacheItemPoolInterface|null $cache = null,
52 bool $isXsdValidationEnabled = true,
53 ): Configuration {
54 $config = self::createConfiguration($isDevMode, $proxyDir, $cache);
55 $config->setMetadataDriverImpl(new XmlDriver($paths, XmlDriver::DEFAULT_FILE_EXTENSION, $isXsdValidationEnabled));
56
57 return $config;
58 }
59
60 /**
61 * Creates a configuration without a metadata driver.
62 */
63 public static function createConfiguration(
64 bool $isDevMode = false,
65 string|null $proxyDir = null,
66 CacheItemPoolInterface|null $cache = null,
67 ): Configuration {
68 $proxyDir = $proxyDir ?: sys_get_temp_dir();
69
70 $cache = self::createCacheInstance($isDevMode, $proxyDir, $cache);
71
72 $config = new Configuration();
73
74 $config->setMetadataCache($cache);
75 $config->setQueryCache($cache);
76 $config->setResultCache($cache);
77 $config->setProxyDir($proxyDir);
78 $config->setProxyNamespace('DoctrineProxies');
79 $config->setAutoGenerateProxyClasses($isDevMode);
80
81 return $config;
82 }
83
84 private static function createCacheInstance(
85 bool $isDevMode,
86 string $proxyDir,
87 CacheItemPoolInterface|null $cache,
88 ): CacheItemPoolInterface {
89 if ($cache !== null) {
90 return $cache;
91 }
92
93 if (! class_exists(ArrayAdapter::class)) {
94 throw new RuntimeException(
95 'The Doctrine setup tool cannot configure caches without symfony/cache.'
96 . ' Please add symfony/cache as explicit dependency or pass your own cache implementation.',
97 );
98 }
99
100 if ($isDevMode) {
101 return new ArrayAdapter();
102 }
103
104 $namespace = 'dc2_' . md5($proxyDir);
105
106 if (extension_loaded('apcu') && apcu_enabled()) {
107 return new ApcuAdapter($namespace);
108 }
109
110 if (MemcachedAdapter::isSupported()) {
111 return new MemcachedAdapter(MemcachedAdapter::createConnection('memcached://127.0.0.1'), $namespace);
112 }
113
114 if (extension_loaded('redis')) {
115 $redis = new Redis();
116 $redis->connect('127.0.0.1');
117
118 return new RedisAdapter($redis, $namespace);
119 }
120
121 return new ArrayAdapter();
122 }
123
124 private function __construct()
125 {
126 }
127}