@@ -56,29 +56,34 @@ protected function configureOptions(OptionsResolver $resolver): void
56
56
protected function configureDefinition (Definition $ definition , array $ options , ?string $ defaultVisibilityForDirectories ): void
57
57
{
58
58
if (isset ($ options ['doctrine_connection ' ])) {
59
- $ bucketDefinition = new Definition (Bucket::class);
60
- $ bucketDefinition ->setFactory ([self ::class, 'initializeBucketFromDocumentManager ' ]);
61
- $ bucketDefinition ->setArguments ([
59
+ if (isset ($ options ['mongodb_uri ' ])) {
60
+ throw new InvalidArgumentException ('In GridFS configuration, "doctrine_connection" and "mongodb_uri" options cannot be set together. ' );
61
+ }
62
+ $ bucket = new Definition (Bucket::class);
63
+ $ bucket ->setFactory ([self ::class, 'initializeBucketFromDocumentManager ' ]);
64
+ $ bucket ->setArguments ([
62
65
new Reference (sprintf ('doctrine_mongodb.odm.%s_document_manager ' , $ options ['doctrine_connection ' ])),
63
66
$ options ['database ' ],
64
67
$ options ['bucket ' ],
65
68
]);
66
69
} elseif (isset ($ options ['mongodb_uri ' ])) {
67
- $ bucketDefinition = new Definition (Bucket::class);
68
- $ bucketDefinition ->setFactory ([self ::class, 'initializeBucketFromConfig ' ]);
69
- $ bucketDefinition ->setArguments ([
70
+ $ bucket = new Definition (Bucket::class);
71
+ $ bucket ->setFactory ([self ::class, 'initializeBucketFromConfig ' ]);
72
+ $ bucket ->setArguments ([
70
73
$ options ['mongodb_uri ' ],
71
74
$ options ['mongodb_uri_options ' ],
72
75
$ options ['mongodb_driver_options ' ],
73
76
$ options ['database ' ] ?? throw new InvalidArgumentException ('MongoDB "database" name is required for Flysystem GridFS configuration ' ),
74
77
$ options ['bucket ' ],
75
78
]);
76
- } elseif (!$ options ['bucket ' ]) {
79
+ } elseif ($ options ['bucket ' ]) {
80
+ $ bucket = new Reference ($ options ['bucket ' ]);
81
+ } else {
77
82
throw new InvalidArgumentException ('Flysystem GridFS configuration requires a "bucket" service name, a "mongodb_uri" or a "doctrine_connection" name ' );
78
83
}
79
84
80
85
$ definition ->setClass (GridFSAdapter::class);
81
- $ definition ->setArgument (0 , $ bucketDefinition ?? new Reference ( $ options [ ' bucket ' ]) );
86
+ $ definition ->setArgument (0 , $ bucket );
82
87
$ definition ->setArgument (1 , $ options ['prefix ' ]);
83
88
}
84
89
0 commit comments