1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Tools; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
8
|
|
|
use Doctrine\Common\Cache\Cache; |
9
|
|
|
use Doctrine\Common\Cache\CacheProvider; |
10
|
|
|
use Doctrine\Common\ClassLoader; |
11
|
|
|
use Doctrine\ORM\Configuration; |
12
|
|
|
use Doctrine\ORM\Mapping\Driver\XmlDriver; |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Convenience class for setting up Doctrine from different installations and configurations. |
16
|
|
|
* |
17
|
|
|
* @author Benjamin Eberlei <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Setup |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Use this method to register all autoloads for a downloaded Doctrine library. |
23
|
|
|
* Pick the directory the library was uncompressed into. |
24
|
|
|
* |
25
|
|
|
* @param string $directory |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public static function registerAutoloadDirectory($directory) |
30
|
|
|
{ |
31
|
|
|
if (!class_exists('Doctrine\Common\ClassLoader', false)) { |
32
|
|
|
require_once $directory . "/Doctrine/Common/ClassLoader.php"; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$loader = new ClassLoader("Doctrine", $directory); |
|
|
|
|
36
|
|
|
$loader->register(); |
37
|
|
|
|
38
|
|
|
$loader = new ClassLoader('Symfony\Component', $directory . "/Doctrine"); |
|
|
|
|
39
|
|
|
$loader->register(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Creates a configuration with an annotation metadata driver. |
44
|
1 |
|
* |
45
|
|
|
* @param array $paths |
46
|
1 |
|
* @param boolean $isDevMode |
47
|
1 |
|
* @param string $proxyDir |
48
|
|
|
* @param Cache $cache |
49
|
|
|
* |
50
|
1 |
|
* @return Configuration |
51
|
1 |
|
*/ |
52
|
|
|
public static function createAnnotationMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null) |
53
|
1 |
|
{ |
54
|
1 |
|
$config = self::createConfiguration($isDevMode, $proxyDir, $cache); |
55
|
1 |
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($paths)); |
56
|
|
|
|
57
|
|
|
return $config; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Creates a configuration with a xml metadata driver. |
62
|
|
|
* |
63
|
|
|
* @param array $paths |
64
|
|
|
* @param boolean $isDevMode |
65
|
|
|
* @param string $proxyDir |
66
|
|
|
* @param Cache $cache |
67
|
|
|
* |
68
|
3 |
|
* @return Configuration |
69
|
|
|
*/ |
70
|
3 |
|
public static function createXMLMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null) |
71
|
3 |
|
{ |
72
|
|
|
$config = self::createConfiguration($isDevMode, $proxyDir, $cache); |
73
|
3 |
|
$config->setMetadataDriverImpl(new XmlDriver($paths)); |
74
|
|
|
|
75
|
|
|
return $config; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Creates a configuration without a metadata driver. |
80
|
|
|
* |
81
|
|
|
* @param bool $isDevMode |
82
|
|
|
* @param string $proxyDir |
83
|
|
|
* @param Cache $cache |
84
|
|
|
* |
85
|
|
|
* @return Configuration |
86
|
1 |
|
*/ |
87
|
|
|
public static function createConfiguration($isDevMode = false, $proxyDir = null, Cache $cache = null) |
88
|
1 |
|
{ |
89
|
1 |
|
$proxyDir = $proxyDir ?: sys_get_temp_dir(); |
90
|
|
|
|
91
|
1 |
|
$cache = self::createCacheConfiguration($isDevMode, $proxyDir, $cache); |
92
|
|
|
|
93
|
|
|
$config = new Configuration(); |
94
|
|
|
$config->setMetadataCacheImpl($cache); |
95
|
|
|
$config->setQueryCacheImpl($cache); |
96
|
|
|
$config->setResultCacheImpl($cache); |
97
|
|
|
$config->setProxyDir($proxyDir); |
98
|
|
|
$config->setProxyNamespace('DoctrineProxies'); |
99
|
|
|
$config->setAutoGenerateProxyClasses($isDevMode); |
100
|
|
|
|
101
|
|
|
return $config; |
102
|
|
|
} |
103
|
5 |
|
|
104
|
|
|
private static function createCacheConfiguration(bool $isDevMode, string $proxyDir, ?Cache $cache) : Cache |
105
|
5 |
|
{ |
106
|
|
|
$cache = self::createCacheInstance($isDevMode, $cache); |
107
|
5 |
|
|
108
|
|
|
if ( ! $cache instanceof CacheProvider) { |
109
|
|
|
return $cache; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$namespace = $cache->getNamespace(); |
113
|
|
|
|
114
|
|
|
if ($namespace !== '') { |
115
|
|
|
$namespace .= ':'; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$cache->setNamespace($namespace . 'dc2_' . md5($proxyDir) . '_'); // to avoid collisions |
119
|
|
|
|
120
|
|
|
return $cache; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
private static function createCacheInstance(bool $isDevMode, ?Cache $cache) : Cache |
124
|
|
|
{ |
125
|
5 |
|
if ($cache !== null) { |
126
|
3 |
|
return $cache; |
127
|
|
|
} |
128
|
|
|
|
129
|
5 |
|
if ($isDevMode === true) { |
130
|
4 |
|
return new ArrayCache(); |
131
|
|
|
} |
132
|
|
|
|
133
|
5 |
|
if (extension_loaded('apc')) { |
134
|
5 |
|
return new \Doctrine\Common\Cache\ApcCache(); |
|
|
|
|
135
|
5 |
|
} |
136
|
5 |
|
|
137
|
5 |
|
if (ini_get('xcache.cacher')) { |
138
|
5 |
|
return new \Doctrine\Common\Cache\XcacheCache(); |
139
|
5 |
|
} |
140
|
|
|
|
141
|
5 |
|
if (extension_loaded('memcache')) { |
142
|
|
|
$memcache = new \Memcache(); |
143
|
|
|
$memcache->connect('127.0.0.1'); |
|
|
|
|
144
|
|
|
|
145
|
|
|
$cache = new \Doctrine\Common\Cache\MemcacheCache(); |
146
|
|
|
$cache->setMemcache($memcache); |
147
|
|
|
|
148
|
|
|
return $cache; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if (extension_loaded('redis')) { |
152
|
|
|
$redis = new \Redis(); |
153
|
|
|
$redis->connect('127.0.0.1'); |
154
|
|
|
|
155
|
|
|
$cache = new \Doctrine\Common\Cache\RedisCache(); |
156
|
|
|
$cache->setRedis($redis); |
157
|
|
|
|
158
|
|
|
return $cache; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
return new ArrayCache(); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths