Skip to content

Commit 9e93ba9

Browse files
committed
Add description to codec interfaces
1 parent 2fe40d2 commit 9e93ba9

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

src/Codec/Codec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
namespace MongoDB\Codec;
1919

2020
/**
21+
* The Codec interface allows decoding BSON data to native PHP types and back
22+
* to BSON.
23+
*
2124
* @psalm-template BSONType
2225
* @psalm-template NativeType
2326
* @template-extends Decoder<BSONType, NativeType>

src/Codec/Decoder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace MongoDB\Codec;
1919

20+
use MongoDB\Exception\InvalidArgumentException;
21+
2022
/**
2123
* @internal
2224
* @psalm-template BSONType
@@ -25,20 +27,31 @@
2527
interface Decoder
2628
{
2729
/**
30+
* Checks if the decoder supports a given value.
31+
*
2832
* @param mixed $value
2933
* @psalm-assert-if-true BSONType $value
3034
*/
3135
public function canDecode($value): bool;
3236

3337
/**
38+
* Decodes a given value. If the decoder does not support the value, it
39+
* should throw an exception.
40+
*
3441
* @param mixed $value
3542
* @psalm-param BSONType $value
3643
* @return mixed
3744
* @psalm-return NativeType
45+
* @throws InvalidArgumentException if the decoder does not support the value
3846
*/
3947
public function decode($value);
4048

4149
/**
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+
*
4255
* @param mixed $value
4356
* @psalm-param mixed $value
4457
* @return mixed

src/Codec/DocumentCodec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use MongoDB\BSON\Document;
2121

2222
/**
23+
* The DocumentCodec interface allows decoding BSON document data to native PHP
24+
* objects and back to BSON documents.
25+
*
2326
* @psalm-template ObjectType of object
2427
* @template-extends Codec<Document, ObjectType>
2528
*/

src/Codec/Encoder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace MongoDB\Codec;
1919

20+
use MongoDB\Exception\InvalidArgumentException;
21+
2022
/**
2123
* @internal
2224
* @psalm-template BSONType
@@ -25,20 +27,31 @@
2527
interface Encoder
2628
{
2729
/**
30+
* Checks if the encoder supports a given value.
31+
*
2832
* @param mixed $value
2933
* @psalm-assert-if-true NativeType $value
3034
*/
3135
public function canEncode($value): bool;
3236

3337
/**
38+
* Encodes a given value. If the encoder does not support the value, it
39+
* should throw an exception.
40+
*
3441
* @param mixed $value
3542
* @psalm-param NativeType $value
3643
* @return mixed
3744
* @psalm-return BSONType
45+
* @throws InvalidArgumentException if the decoder does not support the value
3846
*/
3947
public function encode($value);
4048

4149
/**
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+
*
4255
* @param mixed $value
4356
* @psalm-param mixed $value
4457
* @return mixed

src/Codec/KnowsCodecLibrary.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
namespace MongoDB\Codec;
1919

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+
*/
2025
interface KnowsCodecLibrary
2126
{
2227
public function attachLibrary(CodecLibrary $library): void;

0 commit comments

Comments
 (0)