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