1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ORM; |
21
|
|
|
|
22
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
23
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
24
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
25
|
|
|
use Doctrine\Common\Annotations\SimpleAnnotationReader; |
26
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
27
|
|
|
use Doctrine\Common\Cache\Cache as CacheDriver; |
28
|
|
|
use Doctrine\Common\Proxy\AbstractProxyFactory; |
29
|
|
|
use Doctrine\ORM\Cache\CacheConfiguration; |
30
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; |
31
|
|
|
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver; |
32
|
|
|
use Doctrine\ORM\Mapping\DefaultNamingStrategy; |
33
|
|
|
use Doctrine\ORM\Mapping\DefaultQuoteStrategy; |
34
|
|
|
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
35
|
|
|
use Doctrine\ORM\Mapping\EntityListenerResolver; |
36
|
|
|
use Doctrine\ORM\Mapping\NamingStrategy; |
37
|
|
|
use Doctrine\ORM\Mapping\QuoteStrategy; |
38
|
|
|
use Doctrine\ORM\Persisters\Entity\EntityPersister; |
39
|
|
|
use Doctrine\ORM\Repository\DefaultRepositoryFactory; |
40
|
|
|
use Doctrine\ORM\Repository\RepositoryFactory; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Configuration container for all configuration options of Doctrine. |
44
|
|
|
* It combines all configuration options from DBAL & ORM. |
45
|
|
|
* |
46
|
|
|
* Internal note: When adding a new configuration option just write a getter/setter pair. |
47
|
|
|
* |
48
|
|
|
* @since 2.0 |
49
|
|
|
* @author Benjamin Eberlei <[email protected]> |
50
|
|
|
* @author Guilherme Blanco <[email protected]> |
51
|
|
|
* @author Jonathan Wage <[email protected]> |
52
|
|
|
* @author Roman Borschel <[email protected]> |
53
|
|
|
*/ |
54
|
|
|
class Configuration extends \Doctrine\DBAL\Configuration |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Sets the directory where Doctrine generates any necessary proxy class files. |
58
|
|
|
* |
59
|
|
|
* @param string $dir |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
2339 |
|
public function setProxyDir($dir) |
64
|
|
|
{ |
65
|
2339 |
|
$this->_attributes['proxyDir'] = $dir; |
66
|
2339 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Gets the directory where Doctrine generates any necessary proxy class files. |
70
|
|
|
* |
71
|
|
|
* @return string|null |
72
|
|
|
*/ |
73
|
2335 |
|
public function getProxyDir() |
74
|
|
|
{ |
75
|
2335 |
|
return isset($this->_attributes['proxyDir']) |
76
|
2335 |
|
? $this->_attributes['proxyDir'] |
77
|
2335 |
|
: null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Gets the strategy for automatically generating proxy classes. |
82
|
|
|
* |
83
|
|
|
* @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. |
84
|
|
|
*/ |
85
|
2337 |
|
public function getAutoGenerateProxyClasses() |
86
|
|
|
{ |
87
|
2337 |
|
return isset($this->_attributes['autoGenerateProxyClasses']) |
88
|
5 |
|
? $this->_attributes['autoGenerateProxyClasses'] |
89
|
2337 |
|
: AbstractProxyFactory::AUTOGENERATE_ALWAYS; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Sets the strategy for automatically generating proxy classes. |
94
|
|
|
* |
95
|
|
|
* @param boolean|int $autoGenerate Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. |
96
|
|
|
* True is converted to AUTOGENERATE_ALWAYS, false to AUTOGENERATE_NEVER. |
97
|
|
|
* |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
15 |
|
public function setAutoGenerateProxyClasses($autoGenerate) |
101
|
|
|
{ |
102
|
15 |
|
$this->_attributes['autoGenerateProxyClasses'] = (int) $autoGenerate; |
103
|
15 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Gets the namespace where proxy classes reside. |
107
|
|
|
* |
108
|
|
|
* @return string|null |
109
|
|
|
*/ |
110
|
2334 |
|
public function getProxyNamespace() |
111
|
|
|
{ |
112
|
2334 |
|
return isset($this->_attributes['proxyNamespace']) |
113
|
2334 |
|
? $this->_attributes['proxyNamespace'] |
114
|
2334 |
|
: null; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Sets the namespace where proxy classes reside. |
119
|
|
|
* |
120
|
|
|
* @param string $ns |
121
|
|
|
* |
122
|
|
|
* @return void |
123
|
|
|
*/ |
124
|
2339 |
|
public function setProxyNamespace($ns) |
125
|
|
|
{ |
126
|
2339 |
|
$this->_attributes['proxyNamespace'] = $ns; |
127
|
2339 |
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Sets the cache driver implementation that is used for metadata caching. |
131
|
|
|
* |
132
|
|
|
* @param MappingDriver $driverImpl |
133
|
|
|
* |
134
|
|
|
* @return void |
135
|
|
|
* |
136
|
|
|
* @todo Force parameter to be a Closure to ensure lazy evaluation |
137
|
|
|
* (as soon as a metadata cache is in effect, the driver never needs to initialize). |
138
|
|
|
*/ |
139
|
2338 |
|
public function setMetadataDriverImpl(MappingDriver $driverImpl) |
140
|
|
|
{ |
141
|
2338 |
|
$this->_attributes['metadataDriverImpl'] = $driverImpl; |
142
|
2338 |
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader |
146
|
|
|
* is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported. |
147
|
|
|
* |
148
|
|
|
* @param array $paths |
149
|
|
|
* @param bool $useSimpleAnnotationReader |
150
|
|
|
* |
151
|
|
|
* @return AnnotationDriver |
152
|
|
|
*/ |
153
|
2314 |
|
public function newDefaultAnnotationDriver($paths = array(), $useSimpleAnnotationReader = true) |
154
|
|
|
{ |
155
|
2314 |
|
AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php'); |
156
|
|
|
|
157
|
2314 |
|
if ($useSimpleAnnotationReader) { |
158
|
|
|
// Register the ORM Annotations in the AnnotationRegistry |
159
|
2314 |
|
$reader = new SimpleAnnotationReader(); |
160
|
2314 |
|
$reader->addNamespace('Doctrine\ORM\Mapping'); |
161
|
2314 |
|
$cachedReader = new CachedReader($reader, new ArrayCache()); |
162
|
|
|
|
163
|
2314 |
|
return new AnnotationDriver($cachedReader, (array) $paths); |
|
|
|
|
164
|
|
|
} |
165
|
|
|
|
166
|
1 |
|
return new AnnotationDriver( |
167
|
1 |
|
new CachedReader(new AnnotationReader(), new ArrayCache()), |
|
|
|
|
168
|
1 |
|
(array) $paths |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Adds a namespace under a certain alias. |
174
|
|
|
* |
175
|
|
|
* @param string $alias |
176
|
|
|
* @param string $namespace |
177
|
|
|
* |
178
|
|
|
* @return void |
179
|
|
|
*/ |
180
|
8 |
|
public function addEntityNamespace($alias, $namespace) |
181
|
|
|
{ |
182
|
8 |
|
$this->_attributes['entityNamespaces'][$alias] = $namespace; |
183
|
8 |
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Resolves a registered namespace alias to the full namespace. |
187
|
|
|
* |
188
|
|
|
* @param string $entityNamespaceAlias |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
* |
192
|
|
|
* @throws ORMException |
193
|
|
|
*/ |
194
|
13 |
|
public function getEntityNamespace($entityNamespaceAlias) |
195
|
|
|
{ |
196
|
13 |
|
if ( ! isset($this->_attributes['entityNamespaces'][$entityNamespaceAlias])) { |
197
|
1 |
|
throw ORMException::unknownEntityNamespace($entityNamespaceAlias); |
198
|
|
|
} |
199
|
|
|
|
200
|
13 |
|
return trim($this->_attributes['entityNamespaces'][$entityNamespaceAlias], '\\'); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Sets the entity alias map. |
205
|
|
|
* |
206
|
|
|
* @param array $entityNamespaces |
207
|
|
|
* |
208
|
|
|
* @return void |
209
|
|
|
*/ |
210
|
93 |
|
public function setEntityNamespaces(array $entityNamespaces) |
211
|
|
|
{ |
212
|
93 |
|
$this->_attributes['entityNamespaces'] = $entityNamespaces; |
213
|
93 |
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Retrieves the list of registered entity namespace aliases. |
217
|
|
|
* |
218
|
|
|
* @return array |
219
|
|
|
*/ |
220
|
1 |
|
public function getEntityNamespaces() |
221
|
|
|
{ |
222
|
1 |
|
return $this->_attributes['entityNamespaces']; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Gets the cache driver implementation that is used for the mapping metadata. |
227
|
|
|
* |
228
|
|
|
* @return MappingDriver|null |
229
|
|
|
* |
230
|
|
|
* @throws ORMException |
231
|
|
|
*/ |
232
|
1469 |
|
public function getMetadataDriverImpl() |
233
|
|
|
{ |
234
|
1469 |
|
return isset($this->_attributes['metadataDriverImpl']) |
235
|
1469 |
|
? $this->_attributes['metadataDriverImpl'] |
236
|
1469 |
|
: null; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Gets the cache driver implementation that is used for the query cache (SQL cache). |
241
|
|
|
* |
242
|
|
|
* @return \Doctrine\Common\Cache\Cache|null |
243
|
|
|
*/ |
244
|
566 |
|
public function getQueryCacheImpl() |
245
|
|
|
{ |
246
|
566 |
|
return isset($this->_attributes['queryCacheImpl']) |
247
|
565 |
|
? $this->_attributes['queryCacheImpl'] |
248
|
566 |
|
: null; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Sets the cache driver implementation that is used for the query cache (SQL cache). |
253
|
|
|
* |
254
|
|
|
* @param \Doctrine\Common\Cache\Cache $cacheImpl |
255
|
|
|
* |
256
|
|
|
* @return void |
257
|
|
|
*/ |
258
|
2292 |
|
public function setQueryCacheImpl(CacheDriver $cacheImpl) |
259
|
|
|
{ |
260
|
2292 |
|
$this->_attributes['queryCacheImpl'] = $cacheImpl; |
261
|
2292 |
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Gets the cache driver implementation that is used for the hydration cache (SQL cache). |
265
|
|
|
* |
266
|
|
|
* @return \Doctrine\Common\Cache\Cache|null |
267
|
|
|
*/ |
268
|
1 |
|
public function getHydrationCacheImpl() |
269
|
|
|
{ |
270
|
1 |
|
return isset($this->_attributes['hydrationCacheImpl']) |
271
|
1 |
|
? $this->_attributes['hydrationCacheImpl'] |
272
|
1 |
|
: null; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Sets the cache driver implementation that is used for the hydration cache (SQL cache). |
277
|
|
|
* |
278
|
|
|
* @param \Doctrine\Common\Cache\Cache $cacheImpl |
279
|
|
|
* |
280
|
|
|
* @return void |
281
|
|
|
*/ |
282
|
1 |
|
public function setHydrationCacheImpl(CacheDriver $cacheImpl) |
283
|
|
|
{ |
284
|
1 |
|
$this->_attributes['hydrationCacheImpl'] = $cacheImpl; |
285
|
1 |
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Gets the cache driver implementation that is used for metadata caching. |
289
|
|
|
* |
290
|
|
|
* @return \Doctrine\Common\Cache\Cache|null |
291
|
|
|
*/ |
292
|
2341 |
|
public function getMetadataCacheImpl() |
293
|
|
|
{ |
294
|
2341 |
|
return isset($this->_attributes['metadataCacheImpl']) |
295
|
2286 |
|
? $this->_attributes['metadataCacheImpl'] |
296
|
2341 |
|
: null; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Sets the cache driver implementation that is used for metadata caching. |
301
|
|
|
* |
302
|
|
|
* @param \Doctrine\Common\Cache\Cache $cacheImpl |
303
|
|
|
* |
304
|
|
|
* @return void |
305
|
|
|
*/ |
306
|
2292 |
|
public function setMetadataCacheImpl(CacheDriver $cacheImpl) |
307
|
|
|
{ |
308
|
2292 |
|
$this->_attributes['metadataCacheImpl'] = $cacheImpl; |
309
|
2292 |
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Adds a named DQL query to the configuration. |
313
|
|
|
* |
314
|
|
|
* @param string $name The name of the query. |
315
|
|
|
* @param string $dql The DQL query string. |
316
|
|
|
* |
317
|
|
|
* @return void |
318
|
|
|
*/ |
319
|
1 |
|
public function addNamedQuery($name, $dql) |
320
|
|
|
{ |
321
|
1 |
|
$this->_attributes['namedQueries'][$name] = $dql; |
322
|
1 |
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Gets a previously registered named DQL query. |
326
|
|
|
* |
327
|
|
|
* @param string $name The name of the query. |
328
|
|
|
* |
329
|
|
|
* @return string The DQL query. |
330
|
|
|
* |
331
|
|
|
* @throws ORMException |
332
|
|
|
*/ |
333
|
2 |
|
public function getNamedQuery($name) |
334
|
|
|
{ |
335
|
2 |
|
if ( ! isset($this->_attributes['namedQueries'][$name])) { |
336
|
2 |
|
throw ORMException::namedQueryNotFound($name); |
337
|
|
|
} |
338
|
|
|
|
339
|
1 |
|
return $this->_attributes['namedQueries'][$name]; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Adds a named native query to the configuration. |
344
|
|
|
* |
345
|
|
|
* @param string $name The name of the query. |
346
|
|
|
* @param string $sql The native SQL query string. |
347
|
|
|
* @param Query\ResultSetMapping $rsm The ResultSetMapping used for the results of the SQL query. |
348
|
|
|
* |
349
|
|
|
* @return void |
350
|
|
|
*/ |
351
|
1 |
|
public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm) |
352
|
|
|
{ |
353
|
1 |
|
$this->_attributes['namedNativeQueries'][$name] = array($sql, $rsm); |
354
|
1 |
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Gets the components of a previously registered named native query. |
358
|
|
|
* |
359
|
|
|
* @param string $name The name of the query. |
360
|
|
|
* |
361
|
|
|
* @return array A tuple with the first element being the SQL string and the second |
362
|
|
|
* element being the ResultSetMapping. |
363
|
|
|
* |
364
|
|
|
* @throws ORMException |
365
|
|
|
*/ |
366
|
1 |
|
public function getNamedNativeQuery($name) |
367
|
|
|
{ |
368
|
1 |
|
if ( ! isset($this->_attributes['namedNativeQueries'][$name])) { |
369
|
|
|
throw ORMException::namedNativeQueryNotFound($name); |
370
|
|
|
} |
371
|
|
|
|
372
|
1 |
|
return $this->_attributes['namedNativeQueries'][$name]; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* Ensures that this Configuration instance contains settings that are |
377
|
|
|
* suitable for a production environment. |
378
|
|
|
* |
379
|
|
|
* @return void |
380
|
|
|
* |
381
|
|
|
* @throws ORMException If a configuration setting has a value that is not |
382
|
|
|
* suitable for a production environment. |
383
|
|
|
*/ |
384
|
8 |
|
public function ensureProductionSettings() |
385
|
|
|
{ |
386
|
8 |
|
$queryCacheImpl = $this->getQueryCacheImpl(); |
387
|
|
|
|
388
|
8 |
|
if ( ! $queryCacheImpl) { |
389
|
1 |
|
throw ORMException::queryCacheNotConfigured(); |
390
|
|
|
} |
391
|
|
|
|
392
|
7 |
|
if ($queryCacheImpl instanceof ArrayCache) { |
393
|
1 |
|
throw ORMException::queryCacheUsesNonPersistentCache($queryCacheImpl); |
394
|
|
|
} |
395
|
|
|
|
396
|
6 |
|
$metadataCacheImpl = $this->getMetadataCacheImpl(); |
397
|
|
|
|
398
|
6 |
|
if ( ! $metadataCacheImpl) { |
399
|
1 |
|
throw ORMException::metadataCacheNotConfigured(); |
400
|
|
|
} |
401
|
|
|
|
402
|
5 |
|
if ($metadataCacheImpl instanceof ArrayCache) { |
403
|
1 |
|
throw ORMException::metadataCacheUsesNonPersistentCache($metadataCacheImpl); |
404
|
|
|
} |
405
|
|
|
|
406
|
4 |
|
if ($this->getAutoGenerateProxyClasses()) { |
407
|
3 |
|
throw ORMException::proxyClassesAlwaysRegenerating(); |
408
|
|
|
} |
409
|
1 |
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Registers a custom DQL function that produces a string value. |
413
|
|
|
* Such a function can then be used in any DQL statement in any place where string |
414
|
|
|
* functions are allowed. |
415
|
|
|
* |
416
|
|
|
* DQL function names are case-insensitive. |
417
|
|
|
* |
418
|
|
|
* @param string $name Function name. |
419
|
|
|
* @param string|callable $className Class name or a callable that returns the function. |
420
|
|
|
* |
421
|
|
|
* @return void |
422
|
|
|
* |
423
|
|
|
* @throws ORMException |
424
|
|
|
*/ |
425
|
3 |
|
public function addCustomStringFunction($name, $className) |
426
|
|
|
{ |
427
|
3 |
|
if (Query\Parser::isInternalFunction($name)) { |
428
|
1 |
|
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); |
429
|
|
|
} |
430
|
|
|
|
431
|
3 |
|
$this->_attributes['customStringFunctions'][strtolower($name)] = $className; |
432
|
3 |
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Gets the implementation class name of a registered custom string DQL function. |
436
|
|
|
* |
437
|
|
|
* @param string $name |
438
|
|
|
* |
439
|
|
|
* @return string|null |
440
|
|
|
*/ |
441
|
4 |
|
public function getCustomStringFunction($name) |
442
|
|
|
{ |
443
|
4 |
|
$name = strtolower($name); |
444
|
|
|
|
445
|
4 |
|
return isset($this->_attributes['customStringFunctions'][$name]) |
446
|
3 |
|
? $this->_attributes['customStringFunctions'][$name] |
447
|
4 |
|
: null; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Sets a map of custom DQL string functions. |
452
|
|
|
* |
453
|
|
|
* Keys must be function names and values the FQCN of the implementing class. |
454
|
|
|
* The function names will be case-insensitive in DQL. |
455
|
|
|
* |
456
|
|
|
* Any previously added string functions are discarded. |
457
|
|
|
* |
458
|
|
|
* @param array $functions The map of custom DQL string functions. |
459
|
|
|
* |
460
|
|
|
* @return void |
461
|
|
|
*/ |
462
|
1 |
|
public function setCustomStringFunctions(array $functions) |
463
|
|
|
{ |
464
|
1 |
|
foreach ($functions as $name => $className) { |
465
|
1 |
|
$this->addCustomStringFunction($name, $className); |
466
|
|
|
} |
467
|
1 |
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Registers a custom DQL function that produces a numeric value. |
471
|
|
|
* Such a function can then be used in any DQL statement in any place where numeric |
472
|
|
|
* functions are allowed. |
473
|
|
|
* |
474
|
|
|
* DQL function names are case-insensitive. |
475
|
|
|
* |
476
|
|
|
* @param string $name Function name. |
477
|
|
|
* @param string|callable $className Class name or a callable that returns the function. |
478
|
|
|
* |
479
|
|
|
* @return void |
480
|
|
|
* |
481
|
|
|
* @throws ORMException |
482
|
|
|
*/ |
483
|
3 |
|
public function addCustomNumericFunction($name, $className) |
484
|
|
|
{ |
485
|
3 |
|
if (Query\Parser::isInternalFunction($name)) { |
486
|
1 |
|
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); |
487
|
|
|
} |
488
|
|
|
|
489
|
3 |
|
$this->_attributes['customNumericFunctions'][strtolower($name)] = $className; |
490
|
3 |
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* Gets the implementation class name of a registered custom numeric DQL function. |
494
|
|
|
* |
495
|
|
|
* @param string $name |
496
|
|
|
* |
497
|
|
|
* @return string|null |
498
|
|
|
*/ |
499
|
3 |
|
public function getCustomNumericFunction($name) |
500
|
|
|
{ |
501
|
3 |
|
$name = strtolower($name); |
502
|
|
|
|
503
|
3 |
|
return isset($this->_attributes['customNumericFunctions'][$name]) |
504
|
3 |
|
? $this->_attributes['customNumericFunctions'][$name] |
505
|
3 |
|
: null; |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* Sets a map of custom DQL numeric functions. |
510
|
|
|
* |
511
|
|
|
* Keys must be function names and values the FQCN of the implementing class. |
512
|
|
|
* The function names will be case-insensitive in DQL. |
513
|
|
|
* |
514
|
|
|
* Any previously added numeric functions are discarded. |
515
|
|
|
* |
516
|
|
|
* @param array $functions The map of custom DQL numeric functions. |
517
|
|
|
* |
518
|
|
|
* @return void |
519
|
|
|
*/ |
520
|
2 |
|
public function setCustomNumericFunctions(array $functions) |
521
|
|
|
{ |
522
|
2 |
|
foreach ($functions as $name => $className) { |
523
|
1 |
|
$this->addCustomNumericFunction($name, $className); |
524
|
|
|
} |
525
|
2 |
|
} |
526
|
|
|
|
527
|
|
|
/** |
528
|
|
|
* Registers a custom DQL function that produces a date/time value. |
529
|
|
|
* Such a function can then be used in any DQL statement in any place where date/time |
530
|
|
|
* functions are allowed. |
531
|
|
|
* |
532
|
|
|
* DQL function names are case-insensitive. |
533
|
|
|
* |
534
|
|
|
* @param string $name Function name. |
535
|
|
|
* @param string|callable $className Class name or a callable that returns the function. |
536
|
|
|
* |
537
|
|
|
* @return void |
538
|
|
|
* |
539
|
|
|
* @throws ORMException |
540
|
|
|
*/ |
541
|
1 |
|
public function addCustomDatetimeFunction($name, $className) |
542
|
|
|
{ |
543
|
1 |
|
if (Query\Parser::isInternalFunction($name)) { |
544
|
1 |
|
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); |
545
|
|
|
} |
546
|
|
|
|
547
|
1 |
|
$this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className; |
548
|
1 |
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Gets the implementation class name of a registered custom date/time DQL function. |
552
|
|
|
* |
553
|
|
|
* @param string $name |
554
|
|
|
* |
555
|
|
|
* @return string|null |
556
|
|
|
*/ |
557
|
1 |
|
public function getCustomDatetimeFunction($name) |
558
|
|
|
{ |
559
|
1 |
|
$name = strtolower($name); |
560
|
|
|
|
561
|
1 |
|
return isset($this->_attributes['customDatetimeFunctions'][$name]) |
562
|
1 |
|
? $this->_attributes['customDatetimeFunctions'][$name] |
563
|
1 |
|
: null; |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
/** |
567
|
|
|
* Sets a map of custom DQL date/time functions. |
568
|
|
|
* |
569
|
|
|
* Keys must be function names and values the FQCN of the implementing class. |
570
|
|
|
* The function names will be case-insensitive in DQL. |
571
|
|
|
* |
572
|
|
|
* Any previously added date/time functions are discarded. |
573
|
|
|
* |
574
|
|
|
* @param array $functions The map of custom DQL date/time functions. |
575
|
|
|
* |
576
|
|
|
* @return void |
577
|
|
|
*/ |
578
|
1 |
|
public function setCustomDatetimeFunctions(array $functions) |
579
|
|
|
{ |
580
|
1 |
|
foreach ($functions as $name => $className) { |
581
|
1 |
|
$this->addCustomDatetimeFunction($name, $className); |
582
|
|
|
} |
583
|
1 |
|
} |
584
|
|
|
|
585
|
|
|
/** |
586
|
|
|
* Sets the custom hydrator modes in one pass. |
587
|
|
|
* |
588
|
|
|
* @param array $modes An array of ($modeName => $hydrator). |
589
|
|
|
* |
590
|
|
|
* @return void |
591
|
|
|
*/ |
592
|
1 |
|
public function setCustomHydrationModes($modes) |
593
|
|
|
{ |
594
|
1 |
|
$this->_attributes['customHydrationModes'] = array(); |
595
|
|
|
|
596
|
1 |
|
foreach ($modes as $modeName => $hydrator) { |
597
|
1 |
|
$this->addCustomHydrationMode($modeName, $hydrator); |
598
|
|
|
} |
599
|
1 |
|
} |
600
|
|
|
|
601
|
|
|
/** |
602
|
|
|
* Gets the hydrator class for the given hydration mode name. |
603
|
|
|
* |
604
|
|
|
* @param string $modeName The hydration mode name. |
605
|
|
|
* |
606
|
|
|
* @return string|null The hydrator class name. |
607
|
|
|
*/ |
608
|
3 |
|
public function getCustomHydrationMode($modeName) |
609
|
|
|
{ |
610
|
3 |
|
return isset($this->_attributes['customHydrationModes'][$modeName]) |
611
|
3 |
|
? $this->_attributes['customHydrationModes'][$modeName] |
612
|
3 |
|
: null; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* Adds a custom hydration mode. |
617
|
|
|
* |
618
|
|
|
* @param string $modeName The hydration mode name. |
619
|
|
|
* @param string $hydrator The hydrator class name. |
620
|
|
|
* |
621
|
|
|
* @return void |
622
|
|
|
*/ |
623
|
3 |
|
public function addCustomHydrationMode($modeName, $hydrator) |
624
|
|
|
{ |
625
|
3 |
|
$this->_attributes['customHydrationModes'][$modeName] = $hydrator; |
626
|
3 |
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* Sets a class metadata factory. |
630
|
|
|
* |
631
|
|
|
* @param string $cmfName |
632
|
|
|
* |
633
|
|
|
* @return void |
634
|
|
|
*/ |
635
|
1 |
|
public function setClassMetadataFactoryName($cmfName) |
636
|
|
|
{ |
637
|
1 |
|
$this->_attributes['classMetadataFactoryName'] = $cmfName; |
638
|
1 |
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* @return string |
642
|
|
|
*/ |
643
|
2333 |
|
public function getClassMetadataFactoryName() |
644
|
|
|
{ |
645
|
2333 |
|
if ( ! isset($this->_attributes['classMetadataFactoryName'])) { |
646
|
2333 |
|
$this->_attributes['classMetadataFactoryName'] = 'Doctrine\ORM\Mapping\ClassMetadataFactory'; |
647
|
|
|
} |
648
|
|
|
|
649
|
2333 |
|
return $this->_attributes['classMetadataFactoryName']; |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
/** |
653
|
|
|
* Adds a filter to the list of possible filters. |
654
|
|
|
* |
655
|
|
|
* @param string $name The name of the filter. |
656
|
|
|
* @param string $className The class name of the filter. |
657
|
|
|
*/ |
658
|
46 |
|
public function addFilter($name, $className) |
659
|
|
|
{ |
660
|
46 |
|
$this->_attributes['filters'][$name] = $className; |
661
|
46 |
|
} |
662
|
|
|
|
663
|
|
|
/** |
664
|
|
|
* Gets the class name for a given filter name. |
665
|
|
|
* |
666
|
|
|
* @param string $name The name of the filter. |
667
|
|
|
* |
668
|
|
|
* @return string The class name of the filter, or null if it is not |
669
|
|
|
* defined. |
670
|
|
|
*/ |
671
|
45 |
|
public function getFilterClassName($name) |
672
|
|
|
{ |
673
|
45 |
|
return isset($this->_attributes['filters'][$name]) |
674
|
45 |
|
? $this->_attributes['filters'][$name] |
675
|
45 |
|
: null; |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
/** |
679
|
|
|
* Sets default repository class. |
680
|
|
|
* |
681
|
|
|
* @since 2.2 |
682
|
|
|
* |
683
|
|
|
* @param string $className |
684
|
|
|
* |
685
|
|
|
* @return void |
686
|
|
|
* |
687
|
|
|
* @throws ORMException If not is a \Doctrine\Common\Persistence\ObjectRepository |
688
|
|
|
*/ |
689
|
3 |
|
public function setDefaultRepositoryClassName($className) |
690
|
|
|
{ |
691
|
3 |
|
$reflectionClass = new \ReflectionClass($className); |
692
|
|
|
|
693
|
3 |
|
if ( ! $reflectionClass->implementsInterface('Doctrine\Common\Persistence\ObjectRepository')) { |
694
|
1 |
|
throw ORMException::invalidEntityRepository($className); |
695
|
|
|
} |
696
|
|
|
|
697
|
2 |
|
$this->_attributes['defaultRepositoryClassName'] = $className; |
698
|
2 |
|
} |
699
|
|
|
|
700
|
|
|
/** |
701
|
|
|
* Get default repository class. |
702
|
|
|
* |
703
|
|
|
* @since 2.2 |
704
|
|
|
* |
705
|
|
|
* @return string |
706
|
|
|
*/ |
707
|
139 |
|
public function getDefaultRepositoryClassName() |
708
|
|
|
{ |
709
|
139 |
|
return isset($this->_attributes['defaultRepositoryClassName']) |
710
|
2 |
|
? $this->_attributes['defaultRepositoryClassName'] |
711
|
139 |
|
: 'Doctrine\ORM\EntityRepository'; |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* Sets naming strategy. |
716
|
|
|
* |
717
|
|
|
* @since 2.3 |
718
|
|
|
* |
719
|
|
|
* @param NamingStrategy $namingStrategy |
720
|
|
|
* |
721
|
|
|
* @return void |
722
|
|
|
*/ |
723
|
7 |
|
public function setNamingStrategy(NamingStrategy $namingStrategy) |
724
|
|
|
{ |
725
|
7 |
|
$this->_attributes['namingStrategy'] = $namingStrategy; |
726
|
7 |
|
} |
727
|
|
|
|
728
|
|
|
/** |
729
|
|
|
* Gets naming strategy.. |
730
|
|
|
* |
731
|
|
|
* @since 2.3 |
732
|
|
|
* |
733
|
|
|
* @return NamingStrategy |
734
|
|
|
*/ |
735
|
413 |
|
public function getNamingStrategy() |
736
|
|
|
{ |
737
|
413 |
|
if ( ! isset($this->_attributes['namingStrategy'])) { |
738
|
413 |
|
$this->_attributes['namingStrategy'] = new DefaultNamingStrategy(); |
739
|
|
|
} |
740
|
|
|
|
741
|
413 |
|
return $this->_attributes['namingStrategy']; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
/** |
745
|
|
|
* Sets quote strategy. |
746
|
|
|
* |
747
|
|
|
* @since 2.3 |
748
|
|
|
* |
749
|
|
|
* @param \Doctrine\ORM\Mapping\QuoteStrategy $quoteStrategy |
750
|
|
|
* |
751
|
|
|
* @return void |
752
|
|
|
*/ |
753
|
2 |
|
public function setQuoteStrategy(QuoteStrategy $quoteStrategy) |
754
|
|
|
{ |
755
|
2 |
|
$this->_attributes['quoteStrategy'] = $quoteStrategy; |
756
|
2 |
|
} |
757
|
|
|
|
758
|
|
|
/** |
759
|
|
|
* Gets quote strategy. |
760
|
|
|
* |
761
|
|
|
* @since 2.3 |
762
|
|
|
* |
763
|
|
|
* @return \Doctrine\ORM\Mapping\QuoteStrategy |
764
|
|
|
*/ |
765
|
1611 |
|
public function getQuoteStrategy() |
766
|
|
|
{ |
767
|
1611 |
|
if ( ! isset($this->_attributes['quoteStrategy'])) { |
768
|
1611 |
|
$this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy(); |
769
|
|
|
} |
770
|
|
|
|
771
|
1611 |
|
return $this->_attributes['quoteStrategy']; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* Set the entity listener resolver. |
776
|
|
|
* |
777
|
|
|
* @since 2.4 |
778
|
|
|
* @param \Doctrine\ORM\Mapping\EntityListenerResolver $resolver |
779
|
|
|
*/ |
780
|
1 |
|
public function setEntityListenerResolver(EntityListenerResolver $resolver) |
781
|
|
|
{ |
782
|
1 |
|
$this->_attributes['entityListenerResolver'] = $resolver; |
783
|
1 |
|
} |
784
|
|
|
|
785
|
|
|
/** |
786
|
|
|
* Get the entity listener resolver. |
787
|
|
|
* |
788
|
|
|
* @since 2.4 |
789
|
|
|
* @return \Doctrine\ORM\Mapping\EntityListenerResolver |
790
|
|
|
*/ |
791
|
2333 |
|
public function getEntityListenerResolver() |
792
|
|
|
{ |
793
|
2333 |
|
if ( ! isset($this->_attributes['entityListenerResolver'])) { |
794
|
2333 |
|
$this->_attributes['entityListenerResolver'] = new DefaultEntityListenerResolver(); |
795
|
|
|
} |
796
|
|
|
|
797
|
2333 |
|
return $this->_attributes['entityListenerResolver']; |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
/** |
801
|
|
|
* Set the entity repository factory. |
802
|
|
|
* |
803
|
|
|
* @since 2.4 |
804
|
|
|
* @param \Doctrine\ORM\Repository\RepositoryFactory $repositoryFactory |
805
|
|
|
*/ |
806
|
|
|
public function setRepositoryFactory(RepositoryFactory $repositoryFactory) |
807
|
|
|
{ |
808
|
|
|
$this->_attributes['repositoryFactory'] = $repositoryFactory; |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
/** |
812
|
|
|
* Get the entity repository factory. |
813
|
|
|
* |
814
|
|
|
* @since 2.4 |
815
|
|
|
* @return \Doctrine\ORM\Repository\RepositoryFactory |
816
|
|
|
*/ |
817
|
2332 |
|
public function getRepositoryFactory() |
818
|
|
|
{ |
819
|
2332 |
|
return isset($this->_attributes['repositoryFactory']) |
820
|
|
|
? $this->_attributes['repositoryFactory'] |
821
|
2332 |
|
: new DefaultRepositoryFactory(); |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
/** |
825
|
|
|
* @since 2.5 |
826
|
|
|
* |
827
|
|
|
* @return boolean |
828
|
|
|
*/ |
829
|
2333 |
|
public function isSecondLevelCacheEnabled() |
830
|
|
|
{ |
831
|
2333 |
|
return isset($this->_attributes['isSecondLevelCacheEnabled']) |
832
|
275 |
|
? $this->_attributes['isSecondLevelCacheEnabled'] |
833
|
2333 |
|
: false; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
/** |
837
|
|
|
* @since 2.5 |
838
|
|
|
* |
839
|
|
|
* @param boolean $flag |
840
|
|
|
* |
841
|
|
|
* @return void |
842
|
|
|
*/ |
843
|
275 |
|
public function setSecondLevelCacheEnabled($flag = true) |
844
|
|
|
{ |
845
|
275 |
|
$this->_attributes['isSecondLevelCacheEnabled'] = (boolean) $flag; |
846
|
275 |
|
} |
847
|
|
|
|
848
|
|
|
/** |
849
|
|
|
* @since 2.5 |
850
|
|
|
* |
851
|
|
|
* @param \Doctrine\ORM\Cache\CacheConfiguration $cacheConfig |
852
|
|
|
* |
853
|
|
|
* @return void |
854
|
|
|
*/ |
855
|
276 |
|
public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig) |
856
|
|
|
{ |
857
|
276 |
|
$this->_attributes['secondLevelCacheConfiguration'] = $cacheConfig; |
858
|
276 |
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* @since 2.5 |
862
|
|
|
* |
863
|
|
|
* @return \Doctrine\ORM\Cache\CacheConfiguration|null |
864
|
|
|
*/ |
865
|
276 |
|
public function getSecondLevelCacheConfiguration() |
866
|
|
|
{ |
867
|
276 |
|
if ( ! isset($this->_attributes['secondLevelCacheConfiguration']) && $this->isSecondLevelCacheEnabled()) { |
868
|
|
|
$this->_attributes['secondLevelCacheConfiguration'] = new CacheConfiguration(); |
869
|
|
|
} |
870
|
|
|
|
871
|
276 |
|
return isset($this->_attributes['secondLevelCacheConfiguration']) |
872
|
276 |
|
? $this->_attributes['secondLevelCacheConfiguration'] |
873
|
276 |
|
: null; |
874
|
|
|
} |
875
|
|
|
|
876
|
|
|
/** |
877
|
|
|
* Returns query hints, which will be applied to every query in application |
878
|
|
|
* |
879
|
|
|
* @since 2.5 |
880
|
|
|
* |
881
|
|
|
* @return array |
882
|
|
|
*/ |
883
|
943 |
|
public function getDefaultQueryHints() |
884
|
|
|
{ |
885
|
943 |
|
return isset($this->_attributes['defaultQueryHints']) ? $this->_attributes['defaultQueryHints'] : array(); |
886
|
|
|
} |
887
|
|
|
|
888
|
|
|
/** |
889
|
|
|
* Sets array of query hints, which will be applied to every query in application |
890
|
|
|
* |
891
|
|
|
* @since 2.5 |
892
|
|
|
* |
893
|
|
|
* @param array $defaultQueryHints |
894
|
|
|
*/ |
895
|
1 |
|
public function setDefaultQueryHints(array $defaultQueryHints) |
896
|
|
|
{ |
897
|
1 |
|
$this->_attributes['defaultQueryHints'] = $defaultQueryHints; |
898
|
1 |
|
} |
899
|
|
|
|
900
|
|
|
/** |
901
|
|
|
* Gets the value of a default query hint. If the hint name is not recognized, FALSE is returned. |
902
|
|
|
* |
903
|
|
|
* @since 2.5 |
904
|
|
|
* |
905
|
|
|
* @param string $name The name of the hint. |
906
|
|
|
* |
907
|
|
|
* @return mixed The value of the hint or FALSE, if the hint name is not recognized. |
908
|
|
|
*/ |
909
|
|
|
public function getDefaultQueryHint($name) |
910
|
|
|
{ |
911
|
|
|
return isset($this->_attributes['defaultQueryHints'][$name]) |
912
|
|
|
? $this->_attributes['defaultQueryHints'][$name] |
913
|
|
|
: false; |
914
|
|
|
} |
915
|
|
|
|
916
|
|
|
/** |
917
|
|
|
* Sets a default query hint. If the hint name is not recognized, it is silently ignored. |
918
|
|
|
* |
919
|
|
|
* @since 2.5 |
920
|
|
|
* |
921
|
|
|
* @param string $name The name of the hint. |
922
|
|
|
* @param mixed $value The value of the hint. |
923
|
|
|
*/ |
924
|
1 |
|
public function setDefaultQueryHint($name, $value) |
925
|
|
|
{ |
926
|
1 |
|
$this->_attributes['defaultQueryHints'][$name] = $value; |
927
|
1 |
|
} |
928
|
|
|
|
929
|
|
|
/** |
930
|
|
|
* Gets the type of the result set root that should be returned. By default its an array, but we can set it as |
931
|
|
|
* 'collection', in which case the ORM returns the collection specified for the entity contained in the result set. |
932
|
|
|
* |
933
|
|
|
* @since 2.5 |
934
|
|
|
* |
935
|
|
|
* @return string $type The name of the type: 'array' or 'collection'. |
936
|
|
|
*/ |
937
|
67 |
|
public function getResultRootType() |
938
|
|
|
{ |
939
|
67 |
|
return isset($this->_attributes['resultRootType']) |
940
|
5 |
|
? $this->_attributes['resultRootType'] |
941
|
67 |
|
: EntityPersister::RESULT_ROOT_TYPE_ARRAY; |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
/** |
945
|
|
|
* Gets the type of the result set root that should be returned. By default its an array, but we can set it as |
946
|
|
|
* 'collection', in which case the ORM returns the collection specified for the entity contained in the result set. |
947
|
|
|
* |
948
|
|
|
* @since 2.5 |
949
|
|
|
* |
950
|
|
|
* @param string $type The name of the type: 'array' or 'collection'. |
951
|
|
|
*/ |
952
|
5 |
|
public function setResultRootType($type) |
953
|
|
|
{ |
954
|
5 |
|
$this->_attributes['resultRootType'] = $type; |
955
|
5 |
|
} |
956
|
|
|
} |
957
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: