Browse Source

Use internal class instead of now-removed internal function (#301)

Andreas Braun 2 years ago
parent
commit
05ebfb3119
1 changed files with 15 additions and 2 deletions
  1. 15 2
      lib/Mongo/MongoCollection.php

+ 15 - 2
lib/Mongo/MongoCollection.php

@@ -21,6 +21,7 @@ use Alcaeus\MongoDbAdapter\Helper;
 use Alcaeus\MongoDbAdapter\TypeConverter;
 use Alcaeus\MongoDbAdapter\ExceptionConverter;
 use MongoDB\Driver\Exception\CommandException;
+use MongoDB\Model\IndexInput;
 
 /**
  * Represents a database collection.
@@ -597,7 +598,7 @@ class MongoCollection
         }
 
         if (! isset($options['name'])) {
-            $options['name'] = \MongoDB\generate_index_name($keys);
+            $options['name'] = $this->generateIndexName($keys);
         }
 
         $indexes = iterator_to_array($this->collection->listIndexes());
@@ -677,7 +678,7 @@ class MongoCollection
                 $indexName .= '_1';
             }
         } elseif (is_array($keys)) {
-            $indexName = \MongoDB\generate_index_name($keys);
+            $indexName = $this->generateIndexName($keys);
         } else {
             throw new \InvalidArgumentException();
         }
@@ -1039,6 +1040,18 @@ class MongoCollection
         }
     }
 
+
+    /**
+     * @param array $keys Field or fields to use as index.
+     * @return string
+     */
+    private function generateIndexName($keys)
+    {
+        $indexInput = new IndexInput(['key' => $keys]);
+
+        return (string) $indexInput;
+    }
+
     /**
      * @return array
      */