Commit 6ee316a8 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #103

parents f8362dc3 3cd69949
......@@ -170,6 +170,10 @@ class Database
*/
public function createCollection($collectionName, array $options = [])
{
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
$operation = new CreateCollection($this->databaseName, $collectionName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......
......@@ -51,6 +51,9 @@ class CreateCollection implements Executable
*
* * storageEngine (document): Storage engine options.
*
* * typeMap (array): Type map for BSON deserialization. This will only be
* used for the returned command result document.
*
* * validationAction (string): Validation action.
*
* * validationLevel (string): Validation level.
......@@ -98,6 +101,10 @@ class CreateCollection implements Executable
throw InvalidArgumentException::invalidType('"storageEngine" option', $options['storageEngine'], 'array or object');
}
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
}
if (isset($options['validationAction']) && ! is_string($options['validationAction'])) {
throw InvalidArgumentException::invalidType('"validationAction" option', $options['validationAction'], 'string');
}
......@@ -126,6 +133,10 @@ class CreateCollection implements Executable
{
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
if (isset($this->options['typeMap'])) {
$cursor->setTypeMap($this->options['typeMap']);
}
return current($cursor->toArray());
}
......
......@@ -51,6 +51,10 @@ class CreateCollectionTest extends TestCase
$options[][] = ['storageEngine' => $value];
}
foreach ($this->getInvalidArrayValues() as $value) {
$options[][] = ['typeMap' => $value];
}
foreach ($this->getInvalidStringValues() as $value) {
$options[][] = ['validationAction' => $value];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment