1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Kdyby (http://www.kdyby.org) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2008 Filip Procházka ([email protected]) |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the file license.txt that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Kdyby\Doctrine; |
12
|
|
|
|
13
|
|
|
use Doctrine; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Filip Procházka <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
interface Exception |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @author Filip Procházka <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class InvalidStateException extends \RuntimeException implements Exception |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @author Filip Procházka <[email protected]> |
39
|
|
|
*/ |
40
|
|
|
class InvalidArgumentException extends \InvalidArgumentException implements Exception |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @author Filip Procházka <[email protected]> |
49
|
|
|
*/ |
50
|
|
|
class NotSupportedException extends \LogicException implements Exception |
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @author Filip Procházka <[email protected]> |
59
|
|
|
*/ |
60
|
|
|
class StaticClassException extends \LogicException implements Exception |
61
|
|
|
{ |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The exception that is thrown when a requested method or operation is not implemented. |
69
|
|
|
*/ |
70
|
|
|
class NotImplementedException extends \LogicException implements Exception |
71
|
|
|
{ |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* When class is not found |
79
|
|
|
*/ |
80
|
|
|
class MissingClassException extends \LogicException implements Exception |
81
|
|
|
{ |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @author Filip Procházka <[email protected]> |
89
|
|
|
*/ |
90
|
|
|
class UnexpectedValueException extends \UnexpectedValueException implements Exception |
91
|
|
|
{ |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param mixed $list |
95
|
|
|
* @param string|object $class |
96
|
|
|
* @param string $property |
97
|
|
|
* |
98
|
|
|
* @return UnexpectedValueException |
99
|
|
|
*/ |
100
|
|
|
public static function invalidEventValue($list, $class, $property) |
101
|
|
|
{ |
102
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
103
|
|
|
|
104
|
|
|
return new static("Property $class::$$property must be array or NULL, " . gettype($list) . " given."); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string|object $class |
111
|
|
|
* @param string $property |
112
|
|
|
* |
113
|
|
|
* @return UnexpectedValueException |
114
|
|
|
*/ |
115
|
|
|
public static function notACollection($class, $property) |
116
|
|
|
{ |
117
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
118
|
|
|
|
119
|
|
|
return new static("Class property $class::\$$property is not an instance of Doctrine\\Common\\Collections\\Collection."); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string|object $class |
126
|
|
|
* @param string $property |
127
|
|
|
* |
128
|
|
|
* @return UnexpectedValueException |
129
|
|
|
*/ |
130
|
|
|
public static function collectionCannotBeReplaced($class, $property) |
131
|
|
|
{ |
132
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
133
|
|
|
|
134
|
|
|
return new static("Class property $class::\$$property is an instance of Doctrine\\Common\\Collections\\Collection. Use add<property>() and remove<property>() methods to manipulate it or declare your own."); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @author Filip Procházka <[email protected]> |
143
|
|
|
*/ |
144
|
|
|
class MemberAccessException extends \LogicException implements Exception |
145
|
|
|
{ |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $type |
149
|
|
|
* @param string|object $class |
150
|
|
|
* @param string $property |
151
|
|
|
* |
152
|
|
|
* @return MemberAccessException |
153
|
|
|
*/ |
154
|
|
|
public static function propertyNotWritable($type, $class, $property) |
155
|
|
|
{ |
156
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
157
|
|
|
|
158
|
|
|
return new static("Cannot write to $type property $class::\$$property."); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param string|object $class |
165
|
|
|
* |
166
|
|
|
* @return MemberAccessException |
167
|
|
|
*/ |
168
|
|
|
public static function propertyWriteWithoutName($class) |
169
|
|
|
{ |
170
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
171
|
|
|
|
172
|
|
|
return new static("Cannot write to a class '$class' property without name."); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $type |
179
|
|
|
* @param string|object $class |
180
|
|
|
* @param string $property |
181
|
|
|
* |
182
|
|
|
* @return MemberAccessException |
183
|
|
|
*/ |
184
|
|
|
public static function propertyNotReadable($type, $class, $property) |
185
|
|
|
{ |
186
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
187
|
|
|
|
188
|
|
|
return new static("Cannot read $type property $class::\$$property."); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string|object $class |
195
|
|
|
* |
196
|
|
|
* @return MemberAccessException |
197
|
|
|
*/ |
198
|
|
|
public static function propertyReadWithoutName($class) |
199
|
|
|
{ |
200
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
201
|
|
|
|
202
|
|
|
return new static("Cannot read a class '$class' property without name."); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param string|object $class |
209
|
|
|
* |
210
|
|
|
* @return MemberAccessException |
211
|
|
|
*/ |
212
|
|
|
public static function callWithoutName($class) |
213
|
|
|
{ |
214
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
215
|
|
|
|
216
|
|
|
return new static("Call to class '$class' method without name."); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param object|string $class |
223
|
|
|
* @param string $method |
224
|
|
|
* |
225
|
|
|
* @return MemberAccessException |
226
|
|
|
*/ |
227
|
|
|
public static function undefinedMethodCall($class, $method) |
228
|
|
|
{ |
229
|
|
|
$class = is_object($class) ? get_class($class) : $class; |
230
|
|
|
|
231
|
|
|
return new static("Call to undefined method $class::$method()."); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @author Filip Procházka <[email protected]> |
240
|
|
|
*/ |
241
|
|
|
class QueryException extends \RuntimeException implements Exception |
242
|
|
|
{ |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @var \Doctrine\ORM\Query |
246
|
|
|
*/ |
247
|
|
|
public $query; |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param \Exception $previous |
253
|
|
|
* @param \Doctrine\ORM\AbstractQuery $query |
254
|
|
|
* @param string $message |
255
|
|
|
*/ |
256
|
|
|
public function __construct($previous, Doctrine\ORM\AbstractQuery $query = NULL, $message = "") |
257
|
|
|
{ |
258
|
|
|
parent::__construct($message ?: $previous->getMessage(), 0, $previous); |
259
|
|
|
$this->query = $query; |
|
|
|
|
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @author Filip Procházka <[email protected]> |
268
|
|
|
*/ |
269
|
|
|
class BatchImportException extends \RuntimeException implements Exception |
270
|
|
|
{ |
271
|
|
|
|
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @author Michael Moravec |
278
|
|
|
*/ |
279
|
|
|
class ReadOnlyCollectionException extends NotSupportedException |
280
|
|
|
{ |
281
|
|
|
/** |
282
|
|
|
* @throws ReadOnlyCollectionException |
283
|
|
|
*/ |
284
|
|
|
public static function invalidAccess($what) |
285
|
|
|
{ |
286
|
|
|
return new static('Could not ' . $what . ' read-only collection, write/modify operations are forbidden.'); |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.