Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 78dc173

Browse files
committed
Add description to codec interfaces
1 parent 2df97bb commit 78dc173

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
@@ -3,6 +3,9 @@
33
namespace MongoDB\Codec;
44

55
/**
6+
* The Codec interface allows decoding BSON data to native PHP types and back
7+
* to BSON.
8+
*
69
* @psalm-template BSONType
710
* @psalm-template NativeType
811
* @template-extends Decoder<BSONType, NativeType>

‎src/Codec/Decoder.php‎

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

33
namespace MongoDB\Codec;
44

5+
use MongoDB\Exception\InvalidArgumentException;
6+
57
/**
68
* @internal
79
* @psalm-template BSONType
@@ -10,20 +12,31 @@
1012
interface Decoder
1113
{
1214
/**
15+
* Checks if the decoder supports a given value.
16+
*
1317
* @param mixed $value
1418
* @psalm-assert-if-true BSONType $value
1519
*/
1620
public function canDecode($value): bool;
1721

1822
/**
23+
* Decodes a given value. If the decoder does not support the value, it
24+
* should throw an exception.
25+
*
1926
* @param mixed $value
2027
* @psalm-param BSONType $value
2128
* @return mixed
2229
* @psalm-return NativeType
30+
* @throws InvalidArgumentException if the decoder does not support the value
2331
*/
2432
public function decode($value);
2533

2634
/**
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+
*
2740
* @param mixed $value
2841
* @psalm-param mixed $value
2942
* @return mixed

‎src/Codec/DocumentCodec.php‎

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

77
/**
8+
* The DocumentCodec interface allows decoding BSON document data to native PHP
9+
* objects and back to BSON documents.
10+
*
811
* @psalm-template ObjectType of object
912
* @template-extends Codec<Document, ObjectType>
1013
*/

‎src/Codec/Encoder.php‎

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

33
namespace MongoDB\Codec;
44

5+
use MongoDB\Exception\InvalidArgumentException;
6+
57
/**
68
* @internal
79
* @psalm-template BSONType
@@ -10,20 +12,31 @@
1012
interface Encoder
1113
{
1214
/**
15+
* Checks if the encoder supports a given value.
16+
*
1317
* @param mixed $value
1418
* @psalm-assert-if-true NativeType $value
1519
*/
1620
public function canEncode($value): bool;
1721

1822
/**
23+
* Encodes a given value. If the encoder does not support the value, it
24+
* should throw an exception.
25+
*
1926
* @param mixed $value
2027
* @psalm-param NativeType $value
2128
* @return mixed
2229
* @psalm-return BSONType
30+
* @throws InvalidArgumentException if the decoder does not support the value
2331
*/
2432
public function encode($value);
2533

2634
/**
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+
*
2740
* @param mixed $value
2841
* @psalm-param mixed $value
2942
* @return mixed

‎src/Codec/KnowsCodecLibrary.php‎

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

33
namespace MongoDB\Codec;
44

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /