11
11
use function is_bool ;
12
12
use function is_string ;
13
13
14
- class BulkWriteCommandBuilder
14
+ readonly class BulkWriteCommandBuilder
15
15
{
16
- private BulkWriteCommand $ bulkWriteCommand ;
17
-
18
16
private function __construct (
17
+ public BulkWriteCommand $ bulkWriteCommand ,
19
18
private string $ namespace ,
20
19
private Encoder $ builderEncoder ,
21
20
private ?DocumentCodec $ codec ,
22
- array $ options ,
23
21
) {
22
+ }
23
+
24
+ public static function createWithCollection (Collection $ collection , array $ options ): self
25
+ {
24
26
$ options += ['ordered ' => true ];
25
27
26
28
if (isset ($ options ['bypassDocumentValidation ' ]) && ! is_bool ($ options ['bypassDocumentValidation ' ])) {
@@ -39,26 +41,22 @@ private function __construct(
39
41
throw InvalidArgumentException::invalidType ('"verboseResults" option ' , $ options ['verboseResults ' ], 'boolean ' );
40
42
}
41
43
42
- $ this ->bulkWriteCommand = new BulkWriteCommand ($ options );
43
- }
44
-
45
- public static function createWithCollection (Collection $ collection , array $ options ): self
46
- {
47
44
return new self (
45
+ new BulkWriteCommand ($ options ),
48
46
$ collection ->getNamespace (),
49
47
$ collection ->getBuilderEncoder (),
50
48
$ collection ->getCodec (),
51
- $ options ,
52
49
);
53
50
}
54
51
55
52
public function withCollection (Collection $ collection ): self
56
53
{
57
- $ this ->namespace = $ collection ->getNamespace ();
58
- $ this ->builderEncoder = $ collection ->getBuilderEncoder ();
59
- $ this ->codec = $ collection ->getCodec ();
60
-
61
- return $ this ;
54
+ return new self (
55
+ $ this ->bulkWriteCommand ,
56
+ $ collection ->getNamespace (),
57
+ $ collection ->getBuilderEncoder (),
58
+ $ collection ->getCodec (),
59
+ );
62
60
}
63
61
64
62
public function deleteOne (array |object $ filter , ?array $ options = null ): self
0 commit comments