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