Skip to content

Commit c257e30

Browse files
committed
Introduce interfaces for codecs
1 parent 55c62d3 commit c257e30

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/Codec/Codec.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace MongoDB\Codec;
4+
5+
/**
6+
* @api
7+
*
8+
* @psalm-template B
9+
* @psalm-template T
10+
* @template-extends Decoder<B, T>
11+
* @template-extends Encoder<B, T>
12+
*/
13+
interface Codec extends Decoder, Encoder
14+
{
15+
}

src/Codec/Decoder.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace MongoDB\Codec;
4+
5+
/**
6+
* @api
7+
*
8+
* @psalm-template B
9+
* @psalm-template T
10+
*/
11+
interface Decoder
12+
{
13+
/**
14+
* @param mixed $value
15+
* @psalm-assert-if-true B $value
16+
*/
17+
public function canDecode($value): bool;
18+
19+
/**
20+
* @param mixed $value
21+
* @psalm-param B $value
22+
* @return mixed
23+
* @psalm-return T
24+
*/
25+
public function decode($value);
26+
}

src/Codec/Encoder.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace MongoDB\Codec;
4+
5+
/**
6+
* @api
7+
*
8+
* @psalm-template B
9+
* @psalm-template T
10+
*/
11+
interface Encoder
12+
{
13+
/**
14+
* @param mixed $value
15+
* @psalm-assert-if-true T $value
16+
*/
17+
public function canEncode($value): bool;
18+
19+
/**
20+
* @param mixed $value
21+
* @psalm-param T $value
22+
* @return mixed
23+
* @psalm-return B
24+
*/
25+
public function encode($value);
26+
}

0 commit comments

Comments
 (0)