3737 */
3838class ListCollections implements Executable
3939{
40- private static $ wireVersionForCommand = 3 ;
41-
4240 private $ databaseName ;
4341 private $ options ;
4442
@@ -49,10 +47,6 @@ class ListCollections implements Executable
4947 *
5048 * * filter (document): Query by which to filter collections.
5149 *
52- * For server versions < 3.0, the filter can only be used to match the
53- * "name" field with a string value. More complex filters will result in
54- * an exception at execution time if used.
55- *
5650 * * maxTimeMS (integer): The maximum amount of time to allow the query to
5751 * run.
5852 *
@@ -88,14 +82,11 @@ public function __construct($databaseName, array $options = [])
8882 * @see Executable::execute()
8983 * @param Server $server
9084 * @return CollectionInfoIterator
91- * @throws InvalidArgumentException if filter.name is not a string for legacy execution
9285 * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
9386 */
9487 public function execute (Server $ server )
9588 {
96- return \MongoDB \server_supports_feature ($ server , self ::$ wireVersionForCommand )
97- ? $ this ->executeCommand ($ server )
98- : $ this ->executeLegacy ($ server );
89+ return $ this ->executeCommand ($ server );
9990 }
10091
10192 /**
@@ -143,35 +134,4 @@ private function executeCommand(Server $server)
143134
144135 return new CollectionInfoCommandIterator (new CachingIterator ($ cursor ));
145136 }
146-
147- /**
148- * Returns information for all collections in this database by querying the
149- * "system.namespaces" collection (MongoDB <3.0).
150- *
151- * @param Server $server
152- * @return CollectionInfoLegacyIterator
153- * @throws InvalidArgumentException if filter.name is not a string
154- * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
155- */
156- private function executeLegacy (Server $ server )
157- {
158- $ filter = empty ($ this ->options ['filter ' ]) ? [] : (array ) $ this ->options ['filter ' ];
159-
160- if (array_key_exists ('name ' , $ filter )) {
161- if ( ! is_string ($ filter ['name ' ])) {
162- throw InvalidArgumentException::invalidType ('filter name for MongoDB <3.0 ' , $ filter ['name ' ], 'string ' );
163- }
164-
165- $ filter ['name ' ] = $ this ->databaseName . '. ' . $ filter ['name ' ];
166- }
167-
168- $ options = isset ($ this ->options ['maxTimeMS ' ])
169- ? ['modifiers ' => ['$maxTimeMS ' => $ this ->options ['maxTimeMS ' ]]]
170- : [];
171-
172- $ cursor = $ server ->executeQuery ($ this ->databaseName . '.system.namespaces ' , new Query ($ filter , $ options ));
173- $ cursor ->setTypeMap (['root ' => 'array ' , 'document ' => 'array ' ]);
174-
175- return new CollectionInfoLegacyIterator (new CachingIterator ($ cursor ));
176- }
177137}
0 commit comments