1616use Doctrine \Common \EventSubscriber ;
1717use Doctrine \DBAL \Driver \Middleware ;
1818use Doctrine \DBAL \Logging \Middleware as LoggingMiddleware ;
19+ use Doctrine \DBAL \Types \Type ;
20+ use Doctrine \ORM \Configuration ;
1921use Doctrine \ORM \Mapping \NamingStrategy ;
22+ use Doctrine \ORM \Mapping \UnderscoreNamingStrategy ;
2023use Doctrine \ORM \Proxy \ProxyFactory ;
24+ use Doctrine \ORM \Query \AST \Functions \FunctionNode ;
2125use Psr \Cache \CacheItemPoolInterface ;
2226use Psr \Log \LoggerInterface ;
2327use SensitiveParameter ;
28+ use Symfony \Component \Cache \Adapter \ArrayAdapter ;
2429
2530final readonly class EntityManagerParameters implements EntityManagerParametersInterface
2631{
@@ -29,20 +34,34 @@ public function __construct(
2934 #[SensitiveParameter]
3035 private string $ dsn ,
3136 /** @var array<array-key, string> */
32- private array $ entityDirectories ,
33- private string $ proxyDirectory ,
34- private string $ proxyNamespace ,
35- /** @var ProxyFactory::AUTOGENERATE_* */
36- private int $ proxyAutogenerate ,
37- private CacheItemPoolInterface $ metadataCache ,
38- private CacheItemPoolInterface $ queryCache ,
39- private CacheItemPoolInterface $ resultCache ,
40- private NamingStrategy $ namingStrategy ,
41- private ?LoggerInterface $ logger = null ,
42- /** @var array<string, EventSubscriber> */
43- private array $ eventSubscribers = [],
37+ private array $ entityDirectories = [],
38+ private ?NamingStrategy $ namingStrategy = null ,
39+ /** @var array<array-key, callable(mixed):bool> */
40+ private array $ schemaAssetFilters = [],
41+ /** @var list<class-string> */
42+ private array $ schemaIgnoreClasses = [],
43+ private ?string $ proxyDirectory = null ,
44+ private ?string $ proxyNamespace = null ,
45+ /** @var (ProxyFactory::AUTOGENERATE_*)|null */
46+ private ?int $ proxyAutogenerate = null ,
47+ private ?CacheItemPoolInterface $ metadataCache = null ,
48+ private ?CacheItemPoolInterface $ queryCache = null ,
49+ private ?CacheItemPoolInterface $ resultCache = null ,
50+ /** @var array<string, class-string<FunctionNode>|callable(string):FunctionNode> */
51+ private array $ customDatetimeFunctions = [],
52+ /** @var array<string, class-string<FunctionNode>|callable(string):FunctionNode> */
53+ private array $ customNumericFunctions = [],
54+ /** @var array<string, class-string<FunctionNode>|callable(string):FunctionNode> */
55+ private array $ customStringFunctions = [],
4456 /** @var array<array-key, Middleware> */
4557 private array $ middlewares = [],
58+ /** @var array<string, EventSubscriber> */
59+ private array $ eventSubscribers = [],
60+ /** @var array<array-key, callable(Configuration):void> */
61+ private array $ configurators = [],
62+ /** @var array<string, class-string<Type>> */
63+ private array $ types = [],
64+ private ?LoggerInterface $ logger = null ,
4665 ) {
4766 }
4867
@@ -64,55 +83,90 @@ public function getEntityDirectories(): array
6483 return $ this ->entityDirectories ;
6584 }
6685
86+ public function getNamingStrategy (): NamingStrategy
87+ {
88+ return $ this ->namingStrategy ?? new UnderscoreNamingStrategy ();
89+ }
90+
91+ /**
92+ * @inheritDoc
93+ */
94+ public function getSchemaAssetsFilter (): callable
95+ {
96+ return function (mixed $ asset ): bool {
97+ foreach ($ this ->schemaAssetFilters as $ filter ) {
98+ if ($ filter ($ asset ) === false ) {
99+ return false ;
100+ }
101+ }
102+
103+ return true ;
104+ };
105+ }
106+
107+ /**
108+ * @inheritDoc
109+ */
110+ public function getSchemaIgnoreClasses (): array
111+ {
112+ return $ this ->schemaIgnoreClasses ;
113+ }
114+
67115 public function getProxyDirectory (): string
68116 {
69- return $ this ->proxyDirectory ;
117+ return $ this ->proxyDirectory ?? \sys_get_temp_dir () . ' /doctrine-proxies ' ;
70118 }
71119
72120 public function getProxyNamespace (): string
73121 {
74- return $ this ->proxyNamespace ;
122+ return $ this ->proxyNamespace ?? ' DoctrineProxies ' ;
75123 }
76124
77125 /**
78126 * @inheritDoc
79127 */
80128 public function getProxyAutogenerate (): int
81129 {
82- return $ this ->proxyAutogenerate ;
130+ return $ this ->proxyAutogenerate ?? ProxyFactory:: AUTOGENERATE_ALWAYS ;
83131 }
84132
85133 public function getMetadataCache (): CacheItemPoolInterface
86134 {
87- return $ this ->metadataCache ;
135+ return $ this ->metadataCache ?? new ArrayAdapter () ;
88136 }
89137
90138 public function getQueryCache (): CacheItemPoolInterface
91139 {
92- return $ this ->queryCache ;
140+ return $ this ->queryCache ?? new ArrayAdapter () ;
93141 }
94142
95143 public function getResultCache (): CacheItemPoolInterface
96144 {
97- return $ this ->resultCache ;
145+ return $ this ->resultCache ?? new ArrayAdapter () ;
98146 }
99147
100- public function getNamingStrategy (): NamingStrategy
148+ /**
149+ * @inheritDoc
150+ */
151+ public function getCustomDatetimeFunctions (): array
101152 {
102- return $ this ->namingStrategy ;
153+ return $ this ->customDatetimeFunctions ;
103154 }
104155
105- public function getLogger (): ?LoggerInterface
156+ /**
157+ * @inheritDoc
158+ */
159+ public function getCustomNumericFunctions (): array
106160 {
107- return $ this ->logger ;
161+ return $ this ->customNumericFunctions ;
108162 }
109163
110164 /**
111165 * @inheritDoc
112166 */
113- public function getEventSubscribers (): array
167+ public function getCustomStringFunctions (): array
114168 {
115- return $ this ->eventSubscribers ;
169+ return $ this ->customStringFunctions ;
116170 }
117171
118172 /**
@@ -128,4 +182,33 @@ public function getMiddlewares(): array
128182
129183 return $ middlewares ;
130184 }
185+
186+ /**
187+ * @inheritDoc
188+ */
189+ public function getEventSubscribers (): array
190+ {
191+ return $ this ->eventSubscribers ;
192+ }
193+
194+ /**
195+ * @inheritDoc
196+ */
197+ public function getConfigurators (): array
198+ {
199+ return $ this ->configurators ;
200+ }
201+
202+ /**
203+ * @inheritDoc
204+ */
205+ public function getTypes (): array
206+ {
207+ return $ this ->types ;
208+ }
209+
210+ public function getLogger (): ?LoggerInterface
211+ {
212+ return $ this ->logger ;
213+ }
131214}
0 commit comments