Skip to content

Commit

Permalink
Use internal class instead of now-removed internal function (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus authored Sep 29, 2023
1 parent a18be0b commit 7d488cc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/Mongo/MongoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Alcaeus\MongoDbAdapter\TypeConverter;
use Alcaeus\MongoDbAdapter\ExceptionConverter;
use MongoDB\Driver\Exception\CommandException;
use MongoDB\Model\IndexInput;

/**
* Represents a database collection.
Expand Down Expand Up @@ -597,7 +598,7 @@ public function createIndex($keys, array $options = [])
}

if (! isset($options['name'])) {
$options['name'] = \MongoDB\generate_index_name($keys);
$options['name'] = $this->generateIndexName($keys);
}

$indexes = iterator_to_array($this->collection->listIndexes());
Expand Down Expand Up @@ -677,7 +678,7 @@ public function deleteIndex($keys)
$indexName .= '_1';
}
} elseif (is_array($keys)) {
$indexName = \MongoDB\generate_index_name($keys);
$indexName = $this->generateIndexName($keys);
} else {
throw new \InvalidArgumentException();
}
Expand Down Expand Up @@ -1039,6 +1040,18 @@ private function checkCollectionName($name)
}
}


/**
* @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
*/
Expand Down

0 comments on commit 7d488cc

Please sign in to comment.