22
22
use Tequila \MongoDB \Exception \UnexpectedResultException ;
23
23
use Tequila \MongoDB \Options \Connection \ConnectionOptions ;
24
24
use Tequila \MongoDB \Options \Driver \DriverOptions ;
25
- use Tequila \MongoDB \Util \StringUtils ;
26
- use Tequila \MongoDB \Util \TypeUtils ;
25
+ use Tequila \MongoDB \Util \TypeUtil ;
27
26
use Tequila \MongoDB \Traits \ReadPreferenceAndConcernsTrait ;
28
27
29
- /**
30
- * Class Client
31
- * @package Tequila\MongoDB
32
- */
33
28
class Connection
34
29
{
35
30
use ReadPreferenceAndConcernsTrait;
@@ -80,7 +75,7 @@ public function __construct(
80
75
*/
81
76
public function executeBulkWrite ($ databaseName , $ collectionName , BulkWrite $ bulk , WriteConcern $ writeConcern = null )
82
77
{
83
- $ namespace = StringUtils:: createNamespace ( $ databaseName, $ collectionName) ;
78
+ $ namespace = $ databaseName . ' . ' . $ collectionName ;
84
79
85
80
return $ this ->manager ->executeBulkWrite ($ namespace , $ bulk , $ writeConcern );
86
81
}
@@ -93,13 +88,11 @@ public function executeBulkWrite($databaseName, $collectionName, BulkWrite $bulk
93
88
*/
94
89
public function executeCommand ($ databaseName , $ commandOptions , ReadPreference $ readPreference = null )
95
90
{
96
- StringUtils::ensureValidDatabaseName ($ databaseName );
97
-
98
91
if (!is_array ($ commandOptions ) && !is_object ($ commandOptions )) {
99
92
throw new InvalidArgumentException (
100
93
sprintf (
101
94
'$commandOptions must be an array or an object, %s given ' ,
102
- TypeUtils ::getType ($ commandOptions )
95
+ TypeUtil ::getType ($ commandOptions )
103
96
)
104
97
);
105
98
}
@@ -117,7 +110,7 @@ public function executeCommand($databaseName, $commandOptions, ReadPreference $r
117
110
$ commandOptions = (array ) $ commandOptions ;
118
111
119
112
if (empty ($ commandOptions )) {
120
- throw new InvalidArgumentException ('$command must not be empty. ' );
113
+ throw new InvalidArgumentException ('$commandOptions must not be empty. ' );
121
114
}
122
115
123
116
if (!$ readPreference ) {
@@ -142,7 +135,7 @@ public function executeCommand($databaseName, $commandOptions, ReadPreference $r
142
135
*/
143
136
public function executeQuery ($ databaseName , $ collectionName , Query $ query , ReadPreference $ readPreference = null )
144
137
{
145
- $ namespace = StringUtils:: createNamespace ( $ databaseName, $ collectionName) ;
138
+ $ namespace = $ databaseName . ' . ' . $ collectionName ;
146
139
147
140
return $ this ->manager ->executeQuery ($ namespace , $ query , $ readPreference );
148
141
}
@@ -155,9 +148,6 @@ public function executeQuery($databaseName, $collectionName, Query $query, ReadP
155
148
*/
156
149
public function createCollection ($ databaseName , $ collectionName , array $ options = [])
157
150
{
158
- StringUtils::ensureValidDatabaseName ($ databaseName );
159
- StringUtils::ensureValidCollectionName ($ collectionName );
160
-
161
151
$ options [CreateCollectionType::getCommandName ()] = $ collectionName ;
162
152
163
153
return $ this
@@ -172,10 +162,7 @@ public function createCollection($databaseName, $collectionName, array $options
172
162
*/
173
163
public function dropCollection ($ databaseName , $ collectionName )
174
164
{
175
- StringUtils::ensureValidDatabaseName ($ databaseName );
176
- StringUtils::ensureValidCollectionName ($ collectionName );
177
-
178
- $ options [DropCollectionType::getCommandName ()] = (string )$ collectionName ;
165
+ $ options [DropCollectionType::getCommandName ()] = $ collectionName ;
179
166
180
167
return $ this
181
168
->buildAndExecuteCommand ($ databaseName , DropCollectionType::class, $ options )
@@ -202,9 +189,6 @@ public function listCollections($databaseName, array $options = [])
202
189
*/
203
190
public function createIndexes ($ databaseName , $ collectionName , array $ indexes )
204
191
{
205
- StringUtils::ensureValidDatabaseName ($ databaseName );
206
- StringUtils::ensureValidCollectionName ($ collectionName );
207
-
208
192
if (empty ($ indexes )) {
209
193
throw new InvalidArgumentException ('$indexes array cannot be empty ' );
210
194
}
@@ -217,7 +201,7 @@ public function createIndexes($databaseName, $collectionName, array $indexes)
217
201
sprintf (
218
202
'$indexes[%d] must be an Index instance, %s given ' ,
219
203
$ i ,
220
- TypeUtils ::getType ($ index )
204
+ TypeUtil ::getType ($ index )
221
205
)
222
206
);
223
207
}
@@ -243,9 +227,6 @@ function (Index $index) {
243
227
*/
244
228
public function createIndex ($ databaseName , $ collectionName , Index $ index )
245
229
{
246
- StringUtils::ensureValidDatabaseName ($ databaseName );
247
- StringUtils::ensureValidCollectionName ($ collectionName );
248
-
249
230
$ result = $ this ->createIndexes ($ databaseName , $ collectionName , [$ index ]);
250
231
251
232
return current ($ result );
@@ -258,9 +239,6 @@ public function createIndex($databaseName, $collectionName, Index $index)
258
239
*/
259
240
public function listIndexes ($ databaseName , $ collectionName )
260
241
{
261
- StringUtils::ensureValidDatabaseName ($ databaseName );
262
- StringUtils::ensureValidCollectionName ($ collectionName );
263
-
264
242
return $ this
265
243
->buildAndExecuteCommand (
266
244
$ databaseName ,
@@ -280,9 +258,6 @@ public function listIndexes($databaseName, $collectionName)
280
258
*/
281
259
public function dropIndex ($ databaseName , $ collectionName , $ index )
282
260
{
283
- StringUtils::ensureValidDatabaseName ($ databaseName );
284
- StringUtils::ensureValidCollectionName ($ collectionName );
285
-
286
261
if (is_string ($ index )) {
287
262
$ indexName = $ index ;
288
263
} else if ($ index instanceof Index) {
@@ -292,8 +267,8 @@ public function dropIndex($databaseName, $collectionName, $index)
292
267
} else {
293
268
throw new InvalidArgumentException (
294
269
sprintf (
295
- '$index must be a string, Index instance or array of index keys, %s given ' ,
296
- TypeUtils ::getType ($ index )
270
+ '$index must be a string, Index instance or an array of index keys, %s given ' ,
271
+ TypeUtil ::getType ($ index )
297
272
)
298
273
);
299
274
}
@@ -316,9 +291,6 @@ public function dropIndex($databaseName, $collectionName, $index)
316
291
*/
317
292
public function dropIndexes ($ databaseName , $ collectionName )
318
293
{
319
- StringUtils::ensureValidDatabaseName ($ databaseName );
320
- StringUtils::ensureValidCollectionName ($ collectionName );
321
-
322
294
$ cursor = $ this ->buildAndExecuteCommand (
323
295
$ databaseName ,
324
296
DropIndexesType::class,
@@ -335,8 +307,6 @@ public function dropIndexes($databaseName, $collectionName)
335
307
*/
336
308
public function dropDatabase ($ databaseName , array $ options = [])
337
309
{
338
- StringUtils::ensureValidDatabaseName ($ databaseName );
339
-
340
310
$ cursor = $ this ->buildAndExecuteCommand ($ databaseName , DropDatabaseType::class, $ options );
341
311
342
312
return $ cursor ->toArray ();
@@ -369,8 +339,6 @@ public function listDatabases(array $options = [])
369
339
*/
370
340
public function selectDatabase ($ databaseName )
371
341
{
372
- StringUtils::ensureValidDatabaseName ($ databaseName );
373
-
374
342
$ db = new Database ($ this , $ databaseName );
375
343
$ db
376
344
->setReadConcern ($ this ->getReadConcern ())
@@ -387,9 +355,6 @@ public function selectDatabase($databaseName)
387
355
*/
388
356
public function selectCollection ($ databaseName , $ collectionName )
389
357
{
390
- StringUtils::ensureValidDatabaseName ($ databaseName );
391
- StringUtils::ensureValidCollectionName ($ collectionName );
392
-
393
358
return $ this ->selectDatabase ($ databaseName )->selectCollection ($ collectionName );
394
359
}
395
360
@@ -399,8 +364,6 @@ public function selectCollection($databaseName, $collectionName)
399
364
*/
400
365
public function createCommandBuilder ($ databaseName )
401
366
{
402
- StringUtils::ensureValidDatabaseName ($ databaseName );
403
-
404
367
if (!isset ($ this ->commandBuilders [$ databaseName ])) {
405
368
$ this ->commandBuilders [$ databaseName ] = new CommandBuilder ($ this , $ databaseName );
406
369
}
0 commit comments