|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ORM; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Cache\Cache as CacheDriver; |
|
8
|
|
|
use Exception; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Base exception class for all ORM exceptions. |
|
12
|
|
|
*/ |
|
13
|
|
|
class ORMException extends Exception |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @return ORMException |
|
17
|
|
|
*/ |
|
18
|
|
|
public static function missingMappingDriverImpl() |
|
19
|
|
|
{ |
|
20
|
|
|
return new self("It's a requirement to specify a Metadata Driver and pass it " . |
|
21
|
|
|
'to Doctrine\\ORM\\Configuration::setMetadataDriverImpl().'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param string $queryName |
|
26
|
|
|
* |
|
27
|
|
|
* @return ORMException |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function namedQueryNotFound($queryName) |
|
30
|
|
|
{ |
|
31
|
|
|
return new self('Could not find a named query by the name "' . $queryName . '"'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param string $nativeQueryName |
|
36
|
|
|
* |
|
37
|
|
|
* @return ORMException |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function namedNativeQueryNotFound($nativeQueryName) |
|
40
|
|
|
{ |
|
41
|
|
|
return new self('Could not find a named native query by the name "' . $nativeQueryName . '"'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
* @param string $field |
|
|
|
|
|
|
45
|
|
|
* |
|
46
|
|
|
* @return ORMException |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function unrecognizedField($field) |
|
49
|
|
|
{ |
|
50
|
|
|
return new self('Unrecognized field: ' . $field); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $class |
|
55
|
|
|
* @param string $association |
|
56
|
|
|
* @param string $given |
|
57
|
|
|
* @param string $expected |
|
58
|
|
|
* |
|
59
|
|
|
* @return \Doctrine\ORM\ORMInvalidArgumentException |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function unexpectedAssociationValue($class, $association, $given, $expected) |
|
62
|
|
|
{ |
|
63
|
|
|
return new self(sprintf('Found entity of type %s on association %s#%s, but expecting %s', $given, $class, $association, $expected)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $className |
|
68
|
|
|
* @param string $field |
|
69
|
|
|
* |
|
70
|
|
|
* @return ORMException |
|
71
|
|
|
*/ |
|
72
|
|
|
public static function invalidOrientation($className, $field) |
|
73
|
|
|
{ |
|
74
|
|
|
return new self('Invalid order by orientation specified for ' . $className . '#' . $field); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return ORMException |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function entityManagerClosed() |
|
81
|
|
|
{ |
|
82
|
|
|
return new self('The EntityManager is closed.'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $mode |
|
87
|
|
|
* |
|
88
|
|
|
* @return ORMException |
|
89
|
|
|
*/ |
|
90
|
|
|
public static function invalidHydrationMode($mode) |
|
91
|
|
|
{ |
|
92
|
|
|
return new self(sprintf("'%s' is an invalid hydration mode.", $mode)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return ORMException |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function mismatchedEventManager() |
|
99
|
|
|
{ |
|
100
|
|
|
return new self('Cannot use different EventManager instances for EntityManager and Connection.'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $methodName |
|
105
|
|
|
* |
|
106
|
|
|
* @return ORMException |
|
107
|
|
|
*/ |
|
108
|
|
|
public static function findByRequiresParameter($methodName) |
|
109
|
|
|
{ |
|
110
|
|
|
return new self("You need to pass a parameter to '" . $methodName . "'"); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param string $entityName |
|
115
|
|
|
* @param string $fieldName |
|
116
|
|
|
* @param string $method |
|
117
|
|
|
* |
|
118
|
|
|
* @return ORMException |
|
119
|
|
|
*/ |
|
120
|
|
|
public static function invalidMagicCall($entityName, $fieldName, $method) |
|
121
|
|
|
{ |
|
122
|
|
|
return new self( |
|
123
|
|
|
"Entity '" . $entityName . "' has no field '" . $fieldName . "'. " . |
|
124
|
|
|
"You can therefore not call '" . $method . "' on the entities' repository" |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param string $entityName |
|
130
|
|
|
* @param string $associationFieldName |
|
131
|
|
|
* |
|
132
|
|
|
* @return ORMException |
|
133
|
|
|
*/ |
|
134
|
|
|
public static function invalidFindByInverseAssociation($entityName, $associationFieldName) |
|
135
|
|
|
{ |
|
136
|
|
|
return new self( |
|
137
|
|
|
"You cannot search for the association field '" . $entityName . '#' . $associationFieldName . "', " . |
|
138
|
|
|
'because it is the inverse side of an association. Find methods only work on owning side associations.' |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return ORMException |
|
144
|
|
|
*/ |
|
145
|
|
|
public static function invalidResultCacheDriver() |
|
146
|
|
|
{ |
|
147
|
|
|
return new self('Invalid result cache driver; it must implement Doctrine\\Common\\Cache\\Cache.'); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return ORMException |
|
152
|
|
|
*/ |
|
153
|
|
|
public static function notSupported() |
|
154
|
|
|
{ |
|
155
|
|
|
return new self('This behaviour is (currently) not supported by Doctrine 2'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return ORMException |
|
160
|
|
|
*/ |
|
161
|
|
|
public static function queryCacheNotConfigured() |
|
162
|
|
|
{ |
|
163
|
|
|
return new self('Query Cache is not configured.'); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return ORMException |
|
168
|
|
|
*/ |
|
169
|
|
|
public static function metadataCacheNotConfigured() |
|
170
|
|
|
{ |
|
171
|
|
|
return new self('Class Metadata Cache is not configured.'); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return ORMException |
|
176
|
|
|
*/ |
|
177
|
|
|
public static function queryCacheUsesNonPersistentCache(CacheDriver $cache) |
|
178
|
|
|
{ |
|
179
|
|
|
return new self('Query Cache uses a non-persistent cache driver, ' . get_class($cache) . '.'); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return ORMException |
|
184
|
|
|
*/ |
|
185
|
|
|
public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache) |
|
186
|
|
|
{ |
|
187
|
|
|
return new self('Metadata Cache uses a non-persistent cache driver, ' . get_class($cache) . '.'); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return ORMException |
|
192
|
|
|
*/ |
|
193
|
|
|
public static function proxyClassesAlwaysRegenerating() |
|
194
|
|
|
{ |
|
195
|
|
|
return new self('Proxy Classes are always regenerating.'); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @param string $className |
|
200
|
|
|
* |
|
201
|
|
|
* @return ORMException |
|
202
|
|
|
*/ |
|
203
|
|
|
public static function invalidEntityRepository($className) |
|
204
|
|
|
{ |
|
205
|
|
|
return new self("Invalid repository class '" . $className . "'. It must be a Doctrine\Common\Persistence\ObjectRepository."); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @param string $className |
|
210
|
|
|
* @param string $fieldName |
|
211
|
|
|
* |
|
212
|
|
|
* @return ORMException |
|
213
|
|
|
*/ |
|
214
|
|
|
public static function missingIdentifierField($className, $fieldName) |
|
215
|
|
|
{ |
|
216
|
|
|
return new self(sprintf('The identifier %s is missing for a query of %s', $fieldName, $className)); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param string $className |
|
221
|
|
|
* @param string[] $fieldNames |
|
222
|
|
|
* |
|
223
|
|
|
* @return ORMException |
|
224
|
|
|
*/ |
|
225
|
|
|
public static function unrecognizedIdentifierFields($className, $fieldNames) |
|
226
|
|
|
{ |
|
227
|
|
|
return new self( |
|
228
|
|
|
"Unrecognized identifier fields: '" . implode("', '", $fieldNames) . "' " . |
|
229
|
|
|
"are not present on class '" . $className . "'." |
|
230
|
|
|
); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @return ORMException |
|
235
|
|
|
*/ |
|
236
|
|
|
public static function cantUseInOperatorOnCompositeKeys() |
|
237
|
|
|
{ |
|
238
|
|
|
return new self("Can't use IN operator on entities that have composite keys."); |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
|