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