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