1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base daft objects. |
4
|
|
|
* |
5
|
|
|
* @author SignpostMarv |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace SignpostMarv\DaftObject\Exceptions; |
10
|
|
|
|
11
|
|
|
use SignpostMarv\DaftObject\DaftJson; |
12
|
|
|
use SignpostMarv\DaftObject\DaftObject; |
13
|
|
|
use SignpostMarv\SprintfExceptionFactory\SprintfExceptionFactory; |
14
|
|
|
use Throwable; |
15
|
|
|
|
16
|
|
|
abstract class Factory extends SprintfExceptionFactory |
17
|
|
|
{ |
18
|
|
|
const SPRINTF_PROPERTY_NOT_THINGABLE = 'Property not %s: %s::$%s'; |
19
|
|
|
|
20
|
|
|
const SPRINTF_THING_DOES_NOT_IMPLEMENT_THING = '%s does not implement %s'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @psalm-param class-string $class |
24
|
|
|
* @psalm-param class-string $doesNotImplementClass |
25
|
|
|
*/ |
26
|
|
|
public static function ClassDoesNotImplementClassException( |
27
|
|
|
string $class, |
28
|
|
|
string $doesNotImplementClass, |
29
|
|
|
int $code = self::DEFAULT_INT_CODE, |
30
|
|
|
Throwable $previous = null |
31
|
|
|
) : ClassDoesNotImplementClassException { |
32
|
|
|
/** |
33
|
|
|
* @var ClassDoesNotImplementClassException |
34
|
|
|
*/ |
35
|
|
|
$out = static::Exception( |
36
|
|
|
ClassDoesNotImplementClassException::class, |
37
|
|
|
$code, |
38
|
|
|
$previous, |
39
|
|
|
ClassDoesNotImplementClassException::class, |
40
|
|
|
self::SPRINTF_THING_DOES_NOT_IMPLEMENT_THING, |
41
|
|
|
$class, |
42
|
|
|
$doesNotImplementClass |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
return $out; |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @psalm-param class-string<DaftObject> $class |
50
|
|
|
*/ |
51
|
|
|
public static function DaftObjectNotDaftJsonBadMethodCallException( |
52
|
|
|
string $class, |
53
|
|
|
int $code = self::DEFAULT_INT_CODE, |
54
|
|
|
Throwable $previous = null |
55
|
|
|
) : DaftObjectNotDaftJsonBadMethodCallException { |
56
|
|
|
/** |
57
|
|
|
* @var DaftObjectNotDaftJsonBadMethodCallException |
58
|
|
|
*/ |
59
|
|
|
$out = static::BadMethodCallException( |
60
|
|
|
DaftObjectNotDaftJsonBadMethodCallException::class, |
61
|
|
|
$code, |
62
|
|
|
$previous, |
63
|
|
|
self::SPRINTF_THING_DOES_NOT_IMPLEMENT_THING, |
64
|
|
|
$class, |
65
|
|
|
DaftJson::class |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
return $out; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @psalm-param class-string $className |
73
|
|
|
*/ |
74
|
|
|
public static function NotPublicGetterPropertyException( |
75
|
|
|
string $className, |
76
|
|
|
string $property, |
77
|
|
|
int $code = self::DEFAULT_INT_CODE, |
78
|
|
|
Throwable $previous = null |
79
|
|
|
) : NotPublicGetterPropertyException { |
80
|
|
|
/** |
81
|
|
|
* @var NotPublicGetterPropertyException |
82
|
|
|
*/ |
83
|
|
|
$out = static::AbstractPropertyNotThingableException( |
84
|
|
|
NotPublicGetterPropertyException::class, |
85
|
|
|
'a public getter', |
86
|
|
|
$className, |
87
|
|
|
$property, |
88
|
|
|
$code, |
89
|
|
|
$previous |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
return $out; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @psalm-param class-string $className |
97
|
|
|
*/ |
98
|
|
|
public static function NotPublicSetterPropertyException( |
99
|
|
|
string $className, |
100
|
|
|
string $property, |
101
|
|
|
int $code = self::DEFAULT_INT_CODE, |
102
|
|
|
Throwable $previous = null |
103
|
|
|
) : NotPublicSetterPropertyException { |
104
|
|
|
/** |
105
|
|
|
* @var NotPublicSetterPropertyException |
106
|
|
|
*/ |
107
|
|
|
$out = static::AbstractPropertyNotThingableException( |
108
|
|
|
NotPublicSetterPropertyException::class, |
109
|
|
|
'a public setter', |
110
|
|
|
$className, |
111
|
|
|
$property, |
112
|
|
|
$code, |
113
|
|
|
$previous |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
return $out; |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @psalm-param class-string $className |
121
|
|
|
*/ |
122
|
|
|
public static function PropertyNotJsonDecodableException( |
123
|
|
|
string $className, |
124
|
|
|
string $property, |
125
|
|
|
int $code = self::DEFAULT_INT_CODE, |
126
|
|
|
Throwable $previous = null |
127
|
|
|
) : PropertyNotJsonDecodableException { |
128
|
|
|
/** |
129
|
|
|
* @var PropertyNotJsonDecodableException |
130
|
|
|
*/ |
131
|
|
|
$out = static::AbstractPropertyNotThingableException( |
132
|
|
|
PropertyNotJsonDecodableException::class, |
133
|
|
|
'json-decodable', |
134
|
|
|
$className, |
135
|
|
|
$property, |
136
|
|
|
$code, |
137
|
|
|
$previous |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
return $out; |
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @psalm-param class-string $className |
145
|
|
|
*/ |
146
|
|
|
public static function PropertyNotJsonDecodableShouldBeArrayException( |
147
|
|
|
string $className, |
148
|
|
|
string $property, |
149
|
|
|
int $code = self::DEFAULT_INT_CODE, |
150
|
|
|
Throwable $previous = null |
151
|
|
|
) : PropertyNotJsonDecodableShouldBeArrayException { |
152
|
|
|
/** |
153
|
|
|
* @var PropertyNotJsonDecodableShouldBeArrayException |
154
|
|
|
*/ |
155
|
|
|
$out = static::AbstractPropertyNotThingableException( |
156
|
|
|
PropertyNotJsonDecodableShouldBeArrayException::class, |
157
|
|
|
'json-decodable (should be an array)', |
158
|
|
|
$className, |
159
|
|
|
$property, |
160
|
|
|
$code, |
161
|
|
|
$previous |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
return $out; |
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @psalm-param class-string $className |
169
|
|
|
*/ |
170
|
|
|
public static function PropertyNotNullableException( |
171
|
|
|
string $className, |
172
|
|
|
string $property, |
173
|
|
|
int $code = self::DEFAULT_INT_CODE, |
174
|
|
|
Throwable $previous = null |
175
|
|
|
) : PropertyNotNullableException { |
176
|
|
|
/** |
177
|
|
|
* @var PropertyNotNullableException |
178
|
|
|
*/ |
179
|
|
|
$out = static::AbstractPropertyNotThingableException( |
180
|
|
|
PropertyNotNullableException::class, |
181
|
|
|
'nullable', |
182
|
|
|
$className, |
183
|
|
|
$property, |
184
|
|
|
$code, |
185
|
|
|
$previous |
186
|
|
|
); |
187
|
|
|
|
188
|
|
|
return $out; |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @psalm-param class-string $className |
193
|
|
|
*/ |
194
|
|
|
public static function PropertyNotRewriteableException( |
195
|
|
|
string $className, |
196
|
|
|
string $property, |
197
|
|
|
int $code = self::DEFAULT_INT_CODE, |
198
|
|
|
Throwable $previous = null |
199
|
|
|
) : PropertyNotRewriteableException { |
200
|
|
|
/** |
201
|
|
|
* @var PropertyNotRewriteableException |
202
|
|
|
*/ |
203
|
|
|
$out = static::AbstractPropertyNotThingableException( |
204
|
|
|
PropertyNotRewriteableException::class, |
205
|
|
|
'rewriteable', |
206
|
|
|
$className, |
207
|
|
|
$property, |
208
|
|
|
$code, |
209
|
|
|
$previous |
210
|
|
|
); |
211
|
|
|
|
212
|
|
|
return $out; |
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @psalm-param class-string<DaftObject> $className |
217
|
|
|
*/ |
218
|
|
|
public static function UndefinedPropertyException( |
219
|
|
|
string $className, |
220
|
|
|
string $property, |
221
|
|
|
int $code = self::DEFAULT_INT_CODE, |
222
|
|
|
Throwable $previous = null |
223
|
|
|
) : UndefinedPropertyException { |
224
|
|
|
/** |
225
|
|
|
* @var UndefinedPropertyException |
226
|
|
|
*/ |
227
|
|
|
$out = static::AbstractPropertyNotThingableException( |
228
|
|
|
UndefinedPropertyException::class, |
229
|
|
|
'defined', |
230
|
|
|
$className, |
231
|
|
|
$property, |
232
|
|
|
$code, |
233
|
|
|
$previous |
234
|
|
|
); |
235
|
|
|
|
236
|
|
|
return $out; |
|
|
|
|
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @psalm-param class-string<AbstractPropertyNotThingableException> $type |
241
|
|
|
*/ |
242
|
|
|
protected static function AbstractPropertyNotThingableException( |
243
|
|
|
string $type, |
244
|
|
|
string $thing, |
245
|
|
|
string $className, |
246
|
|
|
string $property, |
247
|
|
|
int $code = self::DEFAULT_INT_CODE, |
248
|
|
|
Throwable $previous = null |
249
|
|
|
) : AbstractPropertyNotThingableException { |
250
|
|
|
/** |
251
|
|
|
* @var AbstractPropertyNotThingableException |
252
|
|
|
*/ |
253
|
|
|
$out = static::Exception( |
254
|
|
|
$type, |
255
|
|
|
$code, |
256
|
|
|
$previous, |
257
|
|
|
AbstractPropertyNotThingableException::class, |
258
|
|
|
self::SPRINTF_PROPERTY_NOT_THINGABLE, |
259
|
|
|
$thing, |
260
|
|
|
$className, |
261
|
|
|
$property |
262
|
|
|
); |
263
|
|
|
|
264
|
|
|
return $out; |
|
|
|
|
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|