26
26
use function is_bool ;
27
27
use function is_string ;
28
28
29
- class BulkWriteCommandBuilder
29
+ readonly class BulkWriteCommandBuilder
30
30
{
31
- private BulkWriteCommand $ bulkWriteCommand ;
32
-
33
31
private function __construct (
32
+ public BulkWriteCommand $ bulkWriteCommand ,
34
33
private string $ namespace ,
35
34
private Encoder $ builderEncoder ,
36
35
private ?DocumentCodec $ codec ,
37
- array $ options ,
38
36
) {
37
+ }
38
+
39
+ public static function createWithCollection (Collection $ collection , array $ options ): self
40
+ {
39
41
$ options += ['ordered ' => true ];
40
42
41
43
if (isset ($ options ['bypassDocumentValidation ' ]) && ! is_bool ($ options ['bypassDocumentValidation ' ])) {
@@ -54,26 +56,22 @@ private function __construct(
54
56
throw InvalidArgumentException::invalidType ('"verboseResults" option ' , $ options ['verboseResults ' ], 'boolean ' );
55
57
}
56
58
57
- $ this ->bulkWriteCommand = new BulkWriteCommand ($ options );
58
- }
59
-
60
- public static function createWithCollection (Collection $ collection , array $ options ): self
61
- {
62
59
return new self (
60
+ new BulkWriteCommand ($ options ),
63
61
$ collection ->getNamespace (),
64
62
$ collection ->getBuilderEncoder (),
65
63
$ collection ->getCodec (),
66
- $ options ,
67
64
);
68
65
}
69
66
70
67
public function withCollection (Collection $ collection ): self
71
68
{
72
- $ this ->namespace = $ collection ->getNamespace ();
73
- $ this ->builderEncoder = $ collection ->getBuilderEncoder ();
74
- $ this ->codec = $ collection ->getCodec ();
75
-
76
- return $ this ;
69
+ return new self (
70
+ $ this ->bulkWriteCommand ,
71
+ $ collection ->getNamespace (),
72
+ $ collection ->getBuilderEncoder (),
73
+ $ collection ->getCodec (),
74
+ );
77
75
}
78
76
79
77
public function deleteOne (array |object $ filter , ?array $ options = null ): self
0 commit comments