Skip to content

Commit 7d488cc

Browse files
authored
Use internal class instead of now-removed internal function (#301)
1 parent a18be0b commit 7d488cc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/Mongo/MongoCollection.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Alcaeus\MongoDbAdapter\TypeConverter;
2222
use Alcaeus\MongoDbAdapter\ExceptionConverter;
2323
use MongoDB\Driver\Exception\CommandException;
24+
use MongoDB\Model\IndexInput;
2425

2526
/**
2627
* Represents a database collection.
@@ -597,7 +598,7 @@ public function createIndex($keys, array $options = [])
597598
}
598599

599600
if (! isset($options['name'])) {
600-
$options['name'] = \MongoDB\generate_index_name($keys);
601+
$options['name'] = $this->generateIndexName($keys);
601602
}
602603

603604
$indexes = iterator_to_array($this->collection->listIndexes());
@@ -677,7 +678,7 @@ public function deleteIndex($keys)
677678
$indexName .= '_1';
678679
}
679680
} elseif (is_array($keys)) {
680-
$indexName = \MongoDB\generate_index_name($keys);
681+
$indexName = $this->generateIndexName($keys);
681682
} else {
682683
throw new \InvalidArgumentException();
683684
}
@@ -1039,6 +1040,18 @@ private function checkCollectionName($name)
10391040
}
10401041
}
10411042

1043+
1044+
/**
1045+
* @param array $keys Field or fields to use as index.
1046+
* @return string
1047+
*/
1048+
private function generateIndexName($keys)
1049+
{
1050+
$indexInput = new IndexInput(['key' => $keys]);
1051+
1052+
return (string) $indexInput;
1053+
}
1054+
10421055
/**
10431056
* @return array
10441057
*/

0 commit comments

Comments
 (0)