File tree Expand file tree Collapse file tree 7 files changed +70
-4
lines changed Expand file tree Collapse file tree 7 files changed +70
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \Codec ;
4
4
5
+ use MongoDB \Exception \UndecodableValueException ;
6
+
5
7
/**
6
8
* @psalm-template BSONType
7
9
* @psalm-template NativeType
@@ -19,6 +21,7 @@ abstract public function canDecode($value): bool;
19
21
* @psalm-param BSONType $value
20
22
* @return mixed
21
23
* @psalm-return NativeType
24
+ * @throws UndecodableValueException if the decoder does not support the value
22
25
*/
23
26
abstract public function decode ($ value );
24
27
Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \Codec ;
4
4
5
- use MongoDB \Exception \InvalidArgumentException ;
5
+ use MongoDB \Exception \UndecodableValueException ;
6
6
7
7
/**
8
8
* @psalm-template BSONType
@@ -26,7 +26,7 @@ public function canDecode($value): bool;
26
26
* @psalm-param BSONType $value
27
27
* @return mixed
28
28
* @psalm-return NativeType
29
- * @throws InvalidArgumentException if the decoder does not support the value
29
+ * @throws UndecodableValueException if the decoder does not support the value
30
30
*/
31
31
public function decode ($ value );
32
32
Original file line number Diff line number Diff line change 3
3
namespace MongoDB \Codec ;
4
4
5
5
use MongoDB \BSON \Document ;
6
+ use MongoDB \Exception \UndecodableValueException ;
7
+ use MongoDB \Exception \UnencodableValueException ;
6
8
7
9
/**
8
10
* The DocumentCodec interface allows decoding BSON document data to native PHP
@@ -17,12 +19,14 @@ interface DocumentCodec extends Codec
17
19
* @param mixed $value
18
20
* @psalm-param Document $value
19
21
* @psalm-return ObjectType
22
+ * @throws UndecodableValueException if the decoder does not support the value
20
23
*/
21
24
public function decode ($ value ): object ;
22
25
23
26
/**
24
27
* @param mixed $value
25
28
* @psalm-param ObjectType $value
29
+ * @throws UnencodableValueException if the encoder does not support the value
26
30
*/
27
31
public function encode ($ value ): Document ;
28
32
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \Codec ;
4
4
5
+ use MongoDB \Exception \UnencodableValueException ;
6
+
5
7
/**
6
8
* @psalm-template BSONType
7
9
* @psalm-template NativeType
@@ -19,6 +21,7 @@ abstract public function canEncode($value): bool;
19
21
* @psalm-param NativeType $value
20
22
* @return mixed
21
23
* @psalm-return BSONType
24
+ * @throws UnencodableValueException if the encoder does not support the value
22
25
*/
23
26
abstract public function encode ($ value );
24
27
Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \Codec ;
4
4
5
- use MongoDB \Exception \InvalidArgumentException ;
5
+ use MongoDB \Exception \UnencodableValueException ;
6
6
7
7
/**
8
8
* @psalm-template BSONType
@@ -26,7 +26,7 @@ public function canEncode($value): bool;
26
26
* @psalm-param NativeType $value
27
27
* @return mixed
28
28
* @psalm-return BSONType
29
- * @throws InvalidArgumentException if the decoder does not support the value
29
+ * @throws UnencodableValueException if the encoder does not support the value
30
30
*/
31
31
public function encode ($ value );
32
32
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MongoDB \Exception ;
4
+
5
+ use InvalidArgumentException ;
6
+
7
+ use function get_debug_type ;
8
+ use function sprintf ;
9
+
10
+ class UndecodableValueException extends InvalidArgumentException implements Exception
11
+ {
12
+ /** @var mixed */
13
+ private $ value ;
14
+
15
+ /** @param mixed $value */
16
+ public function __construct ($ value )
17
+ {
18
+ parent ::__construct (sprintf ('Could not decode value of type "%s". ' , get_debug_type ($ value )));
19
+
20
+ $ this ->value = $ value ;
21
+ }
22
+
23
+ /** @return mixed */
24
+ public function getValue ()
25
+ {
26
+ return $ this ->value ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MongoDB \Exception ;
4
+
5
+ use InvalidArgumentException ;
6
+
7
+ use function get_debug_type ;
8
+ use function sprintf ;
9
+
10
+ class UnencodableValueException extends InvalidArgumentException implements Exception
11
+ {
12
+ /** @var mixed */
13
+ private $ value ;
14
+
15
+ /** @param mixed $value */
16
+ public function __construct ($ value )
17
+ {
18
+ parent ::__construct (sprintf ('Could not encode value of type "%s". ' , get_debug_type ($ value )));
19
+
20
+ $ this ->value = $ value ;
21
+ }
22
+
23
+ /** @return mixed */
24
+ public function getValue ()
25
+ {
26
+ return $ this ->value ;
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments