File tree Expand file tree Collapse file tree 12 files changed +41
-54
lines changed Expand file tree Collapse file tree 12 files changed +41
-54
lines changed Original file line number Diff line number Diff line change 46
46
<code ><![CDATA[ $encoder->encode($value)]]> </code >
47
47
</MixedReturnStatement >
48
48
</file >
49
- <file src =" src/Builder/Encoder/AbstractExpressionEncoder.php" >
50
- <MixedAssignment >
51
- <code ><![CDATA[ $val]]> </code >
52
- <code ><![CDATA[ $val]]> </code >
53
- <code ><![CDATA[ $value[$key]]]> </code >
54
- </MixedAssignment >
55
- </file >
56
49
<file src =" src/Builder/Encoder/CombinedFieldQueryEncoder.php" >
57
50
<MixedAssignment >
58
51
<code ><![CDATA[ $filter]]> </code >
104
97
<code ><![CDATA[ $value]]> </code >
105
98
</MixedAssignment >
106
99
</file >
100
+ <file src =" src/Builder/Encoder/RecursiveEncode.php" >
101
+ <MixedAssignment >
102
+ <code ><![CDATA[ $val]]> </code >
103
+ <code ><![CDATA[ $val]]> </code >
104
+ <code ><![CDATA[ $value[$key]]]> </code >
105
+ </MixedAssignment >
106
+ </file >
107
107
<file src =" src/Builder/Query.php" >
108
108
<ArgumentTypeCoercion >
109
109
<code ><![CDATA[ $query]]> </code >
Original file line number Diff line number Diff line change 6
6
7
7
use MongoDB \Builder \Encoder \CombinedFieldQueryEncoder ;
8
8
use MongoDB \Builder \Encoder \DictionaryEncoder ;
9
- use MongoDB \Builder \Encoder \ExpressionEncoder ;
10
9
use MongoDB \Builder \Encoder \FieldPathEncoder ;
11
10
use MongoDB \Builder \Encoder \OperatorEncoder ;
12
11
use MongoDB \Builder \Encoder \OutputWindowEncoder ;
30
29
31
30
use function array_key_exists ;
32
31
use function is_object ;
32
+ use function is_string ;
33
33
34
34
/** @template-implements Encoder<stdClass|array|string|int, Pipeline|StageInterface|ExpressionInterface|QueryInterface> */
35
35
final class BuilderEncoder implements Encoder
36
36
{
37
37
/** @template-use EncodeIfSupported<stdClass|array|string|int, Pipeline|StageInterface|ExpressionInterface|QueryInterface> */
38
38
use EncodeIfSupported;
39
39
40
- /** @var array<class-string, class-string<ExpressionEncoder >> */
40
+ /** @var array<class-string, class-string<Encoder >> */
41
41
private array $ defaultEncoders = [
42
42
Pipeline::class => PipelineEncoder::class,
43
43
Variable::class => VariableEncoder::class,
Original file line number Diff line number Diff line change 7
7
use LogicException ;
8
8
use MongoDB \Builder \Type \CombinedFieldQuery ;
9
9
use MongoDB \Codec \EncodeIfSupported ;
10
+ use MongoDB \Codec \Encoder ;
10
11
use MongoDB \Exception \UnsupportedValueException ;
11
12
use stdClass ;
12
13
17
18
use function sprintf ;
18
19
19
20
/**
20
- * @template-extends AbstractExpressionEncoder <stdClass, CombinedFieldQuery>
21
+ * @template-implements Encoder <stdClass, CombinedFieldQuery>
21
22
* @internal
22
23
*/
23
- final class CombinedFieldQueryEncoder extends AbstractExpressionEncoder
24
+ final class CombinedFieldQueryEncoder implements Encoder
24
25
{
25
26
/** @template-use EncodeIfSupported<stdClass, CombinedFieldQuery> */
26
27
use EncodeIfSupported;
28
+ use RecursiveEncode;
27
29
28
30
public function canEncode (mixed $ value ): bool
29
31
{
Original file line number Diff line number Diff line change 6
6
7
7
use MongoDB \Builder \Type \DictionaryInterface ;
8
8
use MongoDB \Codec \EncodeIfSupported ;
9
+ use MongoDB \Codec \Encoder ;
9
10
use MongoDB \Exception \UnsupportedValueException ;
10
11
use stdClass ;
11
12
12
13
/**
13
- * @template-extends AbstractExpressionEncoder <string|int|array|stdClass, DictionaryInterface>
14
+ * @template-implements Encoder <string|int|array|stdClass, DictionaryInterface>
14
15
* @internal
15
16
*/
16
- final class DictionaryEncoder extends AbstractExpressionEncoder
17
+ final class DictionaryEncoder implements Encoder
17
18
{
18
19
/** @template-use EncodeIfSupported<string|int|array|stdClass, DictionaryInterface> */
19
20
use EncodeIfSupported;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6
6
7
7
use MongoDB \Builder \Type \FieldPathInterface ;
8
8
use MongoDB \Codec \EncodeIfSupported ;
9
+ use MongoDB \Codec \Encoder ;
9
10
use MongoDB \Exception \UnsupportedValueException ;
10
11
11
12
/**
12
- * @template-extends AbstractExpressionEncoder <string, FieldPathInterface>
13
+ * @template-implements Encoder <string, FieldPathInterface>
13
14
* @internal
14
15
*/
15
- final class FieldPathEncoder extends AbstractExpressionEncoder
16
+ final class FieldPathEncoder implements Encoder
16
17
{
17
18
/** @template-use EncodeIfSupported<string, FieldPathInterface> */
18
19
use EncodeIfSupported;
Original file line number Diff line number Diff line change 9
9
use MongoDB \Builder \Type \OperatorInterface ;
10
10
use MongoDB \Builder \Type \Optional ;
11
11
use MongoDB \Codec \EncodeIfSupported ;
12
+ use MongoDB \Codec \Encoder ;
12
13
use MongoDB \Exception \UnsupportedValueException ;
13
14
use stdClass ;
14
15
17
18
use function sprintf ;
18
19
19
20
/**
20
- * @template-extends AbstractExpressionEncoder <stdClass, OperatorInterface>
21
+ * @template-implements Encoder <stdClass, OperatorInterface>
21
22
* @internal
22
23
*/
23
- final class OperatorEncoder extends AbstractExpressionEncoder
24
+ final class OperatorEncoder implements Encoder
24
25
{
25
26
/** @template-use EncodeIfSupported<stdClass, OperatorInterface> */
26
27
use EncodeIfSupported;
28
+ use RecursiveEncode;
27
29
28
30
public function canEncode (mixed $ value ): bool
29
31
{
Original file line number Diff line number Diff line change 9
9
use MongoDB \Builder \Type \OutputWindow ;
10
10
use MongoDB \Builder \Type \WindowInterface ;
11
11
use MongoDB \Codec \EncodeIfSupported ;
12
+ use MongoDB \Codec \Encoder ;
12
13
use MongoDB \Exception \UnsupportedValueException ;
13
14
use stdClass ;
14
15
18
19
use function sprintf ;
19
20
20
21
/**
21
- * @template-extends AbstractExpressionEncoder <stdClass, OutputWindow>
22
+ * @template-implements Encoder <stdClass, OutputWindow>
22
23
* @internal
23
24
*/
24
- final class OutputWindowEncoder extends AbstractExpressionEncoder
25
+ final class OutputWindowEncoder implements Encoder
25
26
{
26
27
/** @template-use EncodeIfSupported<stdClass, OutputWindow> */
27
28
use EncodeIfSupported;
29
+ use RecursiveEncode;
28
30
29
31
public function canEncode (mixed $ value ): bool
30
32
{
Original file line number Diff line number Diff line change 6
6
7
7
use MongoDB \Builder \Pipeline ;
8
8
use MongoDB \Codec \EncodeIfSupported ;
9
+ use MongoDB \Codec \Encoder ;
9
10
use MongoDB \Exception \UnsupportedValueException ;
10
11
11
12
/**
12
- * @template-extends AbstractExpressionEncoder <list<mixed>, Pipeline>
13
+ * @template-implements Encoder <list<mixed>, Pipeline>
13
14
* @internal
14
15
*/
15
- final class PipelineEncoder extends AbstractExpressionEncoder
16
+ final class PipelineEncoder implements Encoder
16
17
{
17
18
/** @template-use EncodeIfSupported<list<mixed>, Pipeline> */
18
19
use EncodeIfSupported;
20
+ use RecursiveEncode;
19
21
20
22
/** @psalm-assert-if-true Pipeline $value */
21
23
public function canEncode (mixed $ value ): bool
@@ -32,7 +34,7 @@ public function encode(mixed $value): array
32
34
33
35
$ encoded = [];
34
36
foreach ($ value ->getIterator () as $ stage ) {
35
- $ encoded [] = $ this ->encoder -> encodeIfSupported ($ stage );
37
+ $ encoded [] = $ this ->recursiveEncode ($ stage );
36
38
}
37
39
38
40
return $ encoded ;
Original file line number Diff line number Diff line change 8
8
use MongoDB \Builder \Type \QueryInterface ;
9
9
use MongoDB \Builder \Type \QueryObject ;
10
10
use MongoDB \Codec \EncodeIfSupported ;
11
+ use MongoDB \Codec \Encoder ;
11
12
use MongoDB \Exception \UnsupportedValueException ;
12
13
use stdClass ;
13
14
16
17
use function sprintf ;
17
18
18
19
/**
19
- * @template-extends AbstractExpressionEncoder <stdClass, QueryObject>
20
+ * @template-implements Encoder <stdClass, QueryObject>
20
21
* @internal
21
22
*/
22
- final class QueryEncoder extends AbstractExpressionEncoder
23
+ final class QueryEncoder implements Encoder
23
24
{
24
25
/** @template-use EncodeIfSupported<stdClass, QueryObject> */
25
26
use EncodeIfSupported;
27
+ use RecursiveEncode;
26
28
27
29
public function canEncode (mixed $ value ): bool
28
30
{
Original file line number Diff line number Diff line change 10
10
use function get_object_vars ;
11
11
use function is_array ;
12
12
13
- /**
14
- * @template BSONType of stdClass|array|string|int
15
- * @template NativeType
16
- * @template-implements ExpressionEncoder<BSONType, NativeType>
17
- * @internal
18
- */
19
- abstract class AbstractExpressionEncoder implements ExpressionEncoder
13
+ trait RecursiveEncode
20
14
{
21
15
final public function __construct (protected readonly BuilderEncoder $ encoder )
22
16
{
@@ -31,7 +25,7 @@ final public function __construct(protected readonly BuilderEncoder $encoder)
31
25
*
32
26
* @template T
33
27
*/
34
- final protected function recursiveEncode (mixed $ value ): mixed
28
+ private function recursiveEncode (mixed $ value ): mixed
35
29
{
36
30
if (is_array ($ value )) {
37
31
foreach ($ value as $ key => $ val ) {
Original file line number Diff line number Diff line change 6
6
7
7
use MongoDB \Builder \Expression \Variable ;
8
8
use MongoDB \Codec \EncodeIfSupported ;
9
+ use MongoDB \Codec \Encoder ;
9
10
use MongoDB \Exception \UnsupportedValueException ;
10
11
11
12
/**
12
- * @template-extends AbstractExpressionEncoder <string, Variable>
13
+ * @template-implements Encoder <string, Variable>
13
14
* @internal
14
15
*/
15
- final class VariableEncoder extends AbstractExpressionEncoder
16
+ final class VariableEncoder implements Encoder
16
17
{
17
18
/** @template-use EncodeIfSupported<string, Variable> */
18
19
use EncodeIfSupported;
You can’t perform that action at this time.
0 commit comments