5
5
namespace Doctrine \ORM ;
6
6
7
7
use Doctrine \Common \Cache \Cache as CacheDriver ;
8
- use Doctrine \Persistence \ObjectRepository ;
8
+ use Doctrine \ORM \Cache \Exception \InvalidResultCacheDriver ;
9
+ use Doctrine \ORM \Cache \Exception \MetadataCacheNotConfigured ;
10
+ use Doctrine \ORM \Cache \Exception \MetadataCacheUsesNonPersistentCache ;
11
+ use Doctrine \ORM \Cache \Exception \QueryCacheNotConfigured ;
12
+ use Doctrine \ORM \Cache \Exception \QueryCacheUsesNonPersistentCache ;
13
+ use Doctrine \ORM \Exception \EntityManagerClosed ;
14
+ use Doctrine \ORM \Exception \InvalidEntityRepository ;
15
+ use Doctrine \ORM \Exception \InvalidHydrationMode ;
16
+ use Doctrine \ORM \Exception \MismatchedEventManager ;
17
+ use Doctrine \ORM \Exception \MissingIdentifierField ;
18
+ use Doctrine \ORM \Exception \MissingMappingDriverImplementation ;
19
+ use Doctrine \ORM \Exception \NamedNativeQueryNotFound ;
20
+ use Doctrine \ORM \Exception \NamedQueryNotFound ;
21
+ use Doctrine \ORM \Exception \ProxyClassesAlwaysRegenerating ;
22
+ use Doctrine \ORM \Exception \UnexpectedAssociationValue ;
23
+ use Doctrine \ORM \Exception \UnknownEntityNamespace ;
24
+ use Doctrine \ORM \Exception \UnrecognizedIdentifierFields ;
25
+ use Doctrine \ORM \Persisters \Exception \CantUseInOperatorOnCompositeKeys ;
26
+ use Doctrine \ORM \Persisters \Exception \InvalidOrientation ;
27
+ use Doctrine \ORM \Persisters \Exception \UnrecognizedField ;
28
+ use Doctrine \ORM \Repository \Exception \InvalidFindByCall ;
29
+ use Doctrine \ORM \Repository \Exception \InvalidMagicMethodCall ;
30
+ use Doctrine \ORM \Tools \Exception \NotSupported ;
9
31
use Exception ;
10
32
11
- use function get_debug_type ;
12
- use function implode ;
13
33
use function sprintf ;
14
34
15
35
/**
@@ -26,8 +46,7 @@ class ORMException extends Exception
26
46
*/
27
47
public static function missingMappingDriverImpl ()
28
48
{
29
- return new self ("It's a requirement to specify a Metadata Driver and pass it " .
30
- 'to Doctrine \\ORM \\Configuration::setMetadataDriverImpl(). ' );
49
+ return MissingMappingDriverImplementation::create ();
31
50
}
32
51
33
52
/**
@@ -39,19 +58,19 @@ public static function missingMappingDriverImpl()
39
58
*/
40
59
public static function namedQueryNotFound ($ queryName )
41
60
{
42
- return new self ( ' Could not find a named query by the name " ' . $ queryName . ' " ' );
61
+ return NamedQueryNotFound:: fromName ( $ queryName );
43
62
}
44
63
45
64
/**
46
- * @deprecated Use Doctrine\ORM\Exception\NamedQueryNotFound
65
+ * @deprecated Use Doctrine\ORM\Exception\NamedNativeQueryNotFound
47
66
*
48
67
* @param string $nativeQueryName
49
68
*
50
69
* @return ORMException
51
70
*/
52
71
public static function namedNativeQueryNotFound ($ nativeQueryName )
53
72
{
54
- return new self ( ' Could not find a named native query by the name " ' . $ nativeQueryName . ' " ' );
73
+ return NamedNativeQueryNotFound:: fromName ( $ nativeQueryName );
55
74
}
56
75
57
76
/**
@@ -63,7 +82,7 @@ public static function namedNativeQueryNotFound($nativeQueryName)
63
82
*/
64
83
public static function unrecognizedField ($ field )
65
84
{
66
- return new self (sprintf ('Unrecognized field: %s ' , $ field ));
85
+ return new UnrecognizedField (sprintf ('Unrecognized field: %s ' , $ field ));
67
86
}
68
87
69
88
/**
@@ -78,7 +97,7 @@ public static function unrecognizedField($field)
78
97
*/
79
98
public static function unexpectedAssociationValue ($ class , $ association , $ given , $ expected )
80
99
{
81
- return new self ( sprintf ( ' Found entity of type %s on association %s#%s, but expecting %s ' , $ given , $ class , $ association , $ expected) );
100
+ return UnexpectedAssociationValue:: create ( $ class , $ association , $ given , $ expected );
82
101
}
83
102
84
103
/**
@@ -91,7 +110,7 @@ public static function unexpectedAssociationValue($class, $association, $given,
91
110
*/
92
111
public static function invalidOrientation ($ className , $ field )
93
112
{
94
- return new self ( ' Invalid order by orientation specified for ' . $ className . ' # ' . $ field );
113
+ return InvalidOrientation:: fromClassNameAndField ( $ className, $ field );
95
114
}
96
115
97
116
/**
@@ -101,7 +120,7 @@ public static function invalidOrientation($className, $field)
101
120
*/
102
121
public static function entityManagerClosed ()
103
122
{
104
- return new self ( ' The EntityManager is closed. ' );
123
+ return EntityManagerClosed:: create ( );
105
124
}
106
125
107
126
/**
@@ -113,7 +132,7 @@ public static function entityManagerClosed()
113
132
*/
114
133
public static function invalidHydrationMode ($ mode )
115
134
{
116
- return new self ( sprintf ( " '%s' is an invalid hydration mode. " , $ mode) );
135
+ return InvalidHydrationMode:: fromMode ( $ mode );
117
136
}
118
137
119
138
/**
@@ -123,7 +142,7 @@ public static function invalidHydrationMode($mode)
123
142
*/
124
143
public static function mismatchedEventManager ()
125
144
{
126
- return new self ( ' Cannot use different EventManager instances for EntityManager and Connection. ' );
145
+ return MismatchedEventManager:: create ( );
127
146
}
128
147
129
148
/**
@@ -135,11 +154,11 @@ public static function mismatchedEventManager()
135
154
*/
136
155
public static function findByRequiresParameter ($ methodName )
137
156
{
138
- return new self ( " You need to pass a parameter to ' " . $ methodName . " ' " );
157
+ return InvalidMagicMethodCall:: onMissingParameter ( $ methodName );
139
158
}
140
159
141
160
/**
142
- * @deprecated Doctrine\ORM\Repository\Exception\InvalidFindByCall
161
+ * @deprecated Doctrine\ORM\Repository\Exception\InvalidMagicMethodCall::becauseFieldNotFoundIn()
143
162
*
144
163
* @param string $entityName
145
164
* @param string $fieldName
@@ -149,10 +168,7 @@ public static function findByRequiresParameter($methodName)
149
168
*/
150
169
public static function invalidMagicCall ($ entityName , $ fieldName , $ method )
151
170
{
152
- return new self (
153
- "Entity ' " . $ entityName . "' has no field ' " . $ fieldName . "'. " .
154
- "You can therefore not call ' " . $ method . "' on the entities' repository "
155
- );
171
+ return InvalidMagicMethodCall::becauseFieldNotFoundIn ($ entityName , $ fieldName , $ method );
156
172
}
157
173
158
174
/**
@@ -165,10 +181,7 @@ public static function invalidMagicCall($entityName, $fieldName, $method)
165
181
*/
166
182
public static function invalidFindByInverseAssociation ($ entityName , $ associationFieldName )
167
183
{
168
- return new self (
169
- "You cannot search for the association field ' " . $ entityName . '# ' . $ associationFieldName . "', " .
170
- 'because it is the inverse side of an association. Find methods only work on owning side associations. '
171
- );
184
+ return InvalidFindByCall::fromInverseSideUsage ($ entityName , $ associationFieldName );
172
185
}
173
186
174
187
/**
@@ -178,7 +191,7 @@ public static function invalidFindByInverseAssociation($entityName, $association
178
191
*/
179
192
public static function invalidResultCacheDriver ()
180
193
{
181
- return new self ( ' Invalid result cache driver; it must implement Doctrine \\ Common \\ Cache \\ Cache. ' );
194
+ return InvalidResultCacheDriver:: create ( );
182
195
}
183
196
184
197
/**
@@ -188,7 +201,7 @@ public static function invalidResultCacheDriver()
188
201
*/
189
202
public static function notSupported ()
190
203
{
191
- return new self ( ' This behaviour is (currently) not supported by Doctrine 2 ' );
204
+ return NotSupported:: create ( );
192
205
}
193
206
194
207
/**
@@ -198,7 +211,7 @@ public static function notSupported()
198
211
*/
199
212
public static function queryCacheNotConfigured ()
200
213
{
201
- return new self ( ' Query Cache is not configured. ' );
214
+ return QueryCacheNotConfigured:: create ( );
202
215
}
203
216
204
217
/**
@@ -208,7 +221,7 @@ public static function queryCacheNotConfigured()
208
221
*/
209
222
public static function metadataCacheNotConfigured ()
210
223
{
211
- return new self ( ' Class Metadata Cache is not configured. ' );
224
+ return MetadataCacheNotConfigured:: create ( );
212
225
}
213
226
214
227
/**
@@ -218,7 +231,7 @@ public static function metadataCacheNotConfigured()
218
231
*/
219
232
public static function queryCacheUsesNonPersistentCache (CacheDriver $ cache )
220
233
{
221
- return new self ( ' Query Cache uses a non-persistent cache driver, ' . get_debug_type ( $ cache) . ' . ' );
234
+ return QueryCacheUsesNonPersistentCache:: fromDriver ( $ cache );
222
235
}
223
236
224
237
/**
@@ -228,7 +241,7 @@ public static function queryCacheUsesNonPersistentCache(CacheDriver $cache)
228
241
*/
229
242
public static function metadataCacheUsesNonPersistentCache (CacheDriver $ cache )
230
243
{
231
- return new self ( ' Metadata Cache uses a non-persistent cache driver, ' . get_debug_type ( $ cache) . ' . ' );
244
+ return MetadataCacheUsesNonPersistentCache:: fromDriver ( $ cache );
232
245
}
233
246
234
247
/**
@@ -238,7 +251,7 @@ public static function metadataCacheUsesNonPersistentCache(CacheDriver $cache)
238
251
*/
239
252
public static function proxyClassesAlwaysRegenerating ()
240
253
{
241
- return new self ( ' Proxy Classes are always regenerating. ' );
254
+ return ProxyClassesAlwaysRegenerating:: create ( );
242
255
}
243
256
244
257
/**
@@ -250,9 +263,7 @@ public static function proxyClassesAlwaysRegenerating()
250
263
*/
251
264
public static function unknownEntityNamespace ($ entityNamespaceAlias )
252
265
{
253
- return new self (
254
- sprintf ("Unknown Entity namespace alias '%s'. " , $ entityNamespaceAlias )
255
- );
266
+ return UnknownEntityNamespace::fromNamespaceAlias ($ entityNamespaceAlias );
256
267
}
257
268
258
269
/**
@@ -264,11 +275,7 @@ public static function unknownEntityNamespace($entityNamespaceAlias)
264
275
*/
265
276
public static function invalidEntityRepository ($ className )
266
277
{
267
- return new self (sprintf (
268
- "Invalid repository class '%s'. It must be a %s. " ,
269
- $ className ,
270
- ObjectRepository::class
271
- ));
278
+ return InvalidEntityRepository::fromClassName ($ className );
272
279
}
273
280
274
281
/**
@@ -281,7 +288,7 @@ public static function invalidEntityRepository($className)
281
288
*/
282
289
public static function missingIdentifierField ($ className , $ fieldName )
283
290
{
284
- return new self ( sprintf ( ' The identifier %s is missing for a query of %s ' , $ fieldName , $ className) );
291
+ return MissingIdentifierField:: fromFieldAndClass ( $ fieldName , $ className );
285
292
}
286
293
287
294
/**
@@ -294,10 +301,7 @@ public static function missingIdentifierField($className, $fieldName)
294
301
*/
295
302
public static function unrecognizedIdentifierFields ($ className , $ fieldNames )
296
303
{
297
- return new self (
298
- "Unrecognized identifier fields: ' " . implode ("', ' " , $ fieldNames ) . "' " .
299
- "are not present on class ' " . $ className . "'. "
300
- );
304
+ return UnrecognizedIdentifierFields::fromClassAndFieldNames ($ className , $ fieldNames );
301
305
}
302
306
303
307
/**
@@ -307,6 +311,6 @@ public static function unrecognizedIdentifierFields($className, $fieldNames)
307
311
*/
308
312
public static function cantUseInOperatorOnCompositeKeys ()
309
313
{
310
- return new self ( " Can't use IN operator on entities that have composite keys. " );
314
+ return CantUseInOperatorOnCompositeKeys:: create ( );
311
315
}
312
316
}
0 commit comments