17
17
18
18
namespace MongoDB \Operation ;
19
19
20
+ use ArrayIterator ;
20
21
use MongoDB \Driver \Cursor ;
21
22
use MongoDB \Driver \Exception \RuntimeException as DriverRuntimeException ;
22
23
use MongoDB \Driver \Server ;
23
24
use MongoDB \Exception \InvalidArgumentException ;
24
25
use MongoDB \Exception \UnexpectedValueException ;
25
26
use MongoDB \Exception \UnsupportedException ;
26
27
27
- use function array_intersect_key ;
28
28
use function is_array ;
29
- use function is_integer ;
30
29
use function is_object ;
30
+ use function is_string ;
31
+ use function MongoDB \document_to_array ;
31
32
32
33
/**
33
34
* Operation for the listSearchIndexes command.
@@ -49,9 +50,6 @@ class ListSearchIndexes implements Executable
49
50
/** @var array */
50
51
private $ aggregateOptions ;
51
52
52
- /** @var array */
53
- private $ listIndexesOptions ;
54
-
55
53
/** @var Aggregate */
56
54
private $ aggregate ;
57
55
@@ -64,26 +62,25 @@ class ListSearchIndexes implements Executable
64
62
* @param array $options Command options
65
63
* @throws InvalidArgumentException for parameter/option parsing errors
66
64
*/
67
- public function __construct (string $ databaseName , string $ collectionName , array $ filter , array $ options = [])
65
+ public function __construct (string $ databaseName , string $ collectionName , $ filter , array $ options = [])
68
66
{
69
67
if (! is_array ($ filter ) && ! is_object ($ filter )) {
70
68
throw InvalidArgumentException::invalidType ('$filter ' , $ filter , 'array or object ' );
71
69
}
72
70
73
- if (isset ($ options ['limit ' ]) && ! is_integer ($ options ['limit ' ])) {
74
- throw InvalidArgumentException::invalidType ('"limit" option ' , $ options ['limit ' ], 'integer ' );
75
- }
71
+ $ filter = document_to_array ($ filter );
76
72
77
- if (isset ($ options [ ' skip ' ]) && ! is_integer ($ options ['skip ' ])) {
78
- throw InvalidArgumentException::invalidType ('"skip" option ' , $ options [ ' skip ' ], 'integer ' );
73
+ if (isset ($ filter [ ' name ' ]) && ! is_string ($ options ['name ' ])) {
74
+ throw InvalidArgumentException::invalidType ('"name" filter ' , $ filter [ ' name ' ], 'string ' );
79
75
}
80
76
81
77
$ this ->databaseName = $ databaseName ;
82
78
$ this ->collectionName = $ collectionName ;
83
79
$ this ->filter = $ filter ;
84
80
85
- $ this ->aggregateOptions = array_intersect_key ($ options , ['batchSize ' => 1 ]);
86
- $ this ->listIndexesOptions = array_intersect_key ($ options , ['limit ' => 1 , 'skip ' => 1 ]);
81
+ /* There is currently no additional options for the $listSearchIndexes operation, the $options array can be
82
+ * split into two parts: $listIndexesOptions and $aggregateOptions if options are added in the future. */
83
+ $ this ->aggregateOptions = $ options ;
87
84
88
85
$ this ->aggregate = $ this ->createAggregate ();
89
86
}
@@ -92,11 +89,12 @@ public function __construct(string $databaseName, string $collectionName, array
92
89
* Execute the operation.
93
90
*
94
91
* @see Executable::execute()
92
+ * @return ArrayIterator|Cursor
95
93
* @throws UnexpectedValueException if the command response was malformed
96
94
* @throws UnsupportedException if collation or read concern is used and unsupported
97
95
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
98
96
*/
99
- public function execute (Server $ server ): Cursor
97
+ public function execute (Server $ server )
100
98
{
101
99
return $ this ->aggregate ->execute ($ server );
102
100
}
@@ -107,14 +105,6 @@ private function createAggregate(): Aggregate
107
105
['$listSearchIndexes ' => (object ) $ this ->filter ],
108
106
];
109
107
110
- if (isset ($ this ->listIndexesOptions ['skip ' ])) {
111
- $ pipeline [] = ['$skip ' => $ this ->listIndexesOptions ['skip ' ]];
112
- }
113
-
114
- if (isset ($ this ->listIndexesOptions ['limit ' ])) {
115
- $ pipeline [] = ['$limit ' => $ this ->listIndexesOptions ['limit ' ]];
116
- }
117
-
118
108
return new Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ this ->aggregateOptions );
119
109
}
120
110
}
0 commit comments