File tree Expand file tree Collapse file tree 5 files changed +37
-0
lines changed Expand file tree Collapse file tree 5 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 3
3
namespace MongoDB \Codec ;
4
4
5
5
/**
6
+ * The Codec interface allows decoding BSON data to native PHP types and back
7
+ * to BSON.
8
+ *
6
9
* @psalm-template BSONType
7
10
* @psalm-template NativeType
8
11
* @template-extends Decoder<BSONType, NativeType>
Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \Codec ;
4
4
5
+ use MongoDB \Exception \InvalidArgumentException ;
6
+
5
7
/**
6
8
* @internal
7
9
* @psalm-template BSONType
10
12
interface Decoder
11
13
{
12
14
/**
15
+ * Checks if the decoder supports a given value.
16
+ *
13
17
* @param mixed $value
14
18
* @psalm-assert-if-true BSONType $value
15
19
*/
16
20
public function canDecode ($ value ): bool ;
17
21
18
22
/**
23
+ * Decodes a given value. If the decoder does not support the value, it
24
+ * should throw an exception.
25
+ *
19
26
* @param mixed $value
20
27
* @psalm-param BSONType $value
21
28
* @return mixed
22
29
* @psalm-return NativeType
30
+ * @throws InvalidArgumentException if the decoder does not support the value
23
31
*/
24
32
public function decode ($ value );
25
33
26
34
/**
35
+ * Decodes a given value if supported, otherwise returns the value as-is.
36
+ *
37
+ * The DecodeIfSupported trait provides a default implementation of this
38
+ * method.
39
+ *
27
40
* @param mixed $value
28
41
* @psalm-param mixed $value
29
42
* @return mixed
Original file line number Diff line number Diff line change 5
5
use MongoDB \BSON \Document ;
6
6
7
7
/**
8
+ * The DocumentCodec interface allows decoding BSON document data to native PHP
9
+ * objects and back to BSON documents.
10
+ *
8
11
* @psalm-template ObjectType of object
9
12
* @template-extends Codec<Document, ObjectType>
10
13
*/
Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \Codec ;
4
4
5
+ use MongoDB \Exception \InvalidArgumentException ;
6
+
5
7
/**
6
8
* @internal
7
9
* @psalm-template BSONType
10
12
interface Encoder
11
13
{
12
14
/**
15
+ * Checks if the encoder supports a given value.
16
+ *
13
17
* @param mixed $value
14
18
* @psalm-assert-if-true NativeType $value
15
19
*/
16
20
public function canEncode ($ value ): bool ;
17
21
18
22
/**
23
+ * Encodes a given value. If the encoder does not support the value, it
24
+ * should throw an exception.
25
+ *
19
26
* @param mixed $value
20
27
* @psalm-param NativeType $value
21
28
* @return mixed
22
29
* @psalm-return BSONType
30
+ * @throws InvalidArgumentException if the decoder does not support the value
23
31
*/
24
32
public function encode ($ value );
25
33
26
34
/**
35
+ * Encodes a given value if supported, otherwise returns the value as-is.
36
+ *
37
+ * The EncodeIfSupported trait provides a default implementation of this
38
+ * method.
39
+ *
27
40
* @param mixed $value
28
41
* @psalm-param mixed $value
29
42
* @return mixed
Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \Codec ;
4
4
5
+ /**
6
+ * This interface is used to indicate that a class is aware of the CodecLibrary
7
+ * it was added to. The library will be injected when the codec is added to the
8
+ * library. This allows codecs to recursively encode its nested values.
9
+ */
5
10
interface KnowsCodecLibrary
6
11
{
7
12
public function attachLibrary (CodecLibrary $ library ): void ;
You can’t perform that action at this time.
0 commit comments