Commit 3cd69949 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-164: CreateCollection should use type map

parent f8362dc3
...@@ -170,6 +170,10 @@ class Database ...@@ -170,6 +170,10 @@ class Database
*/ */
public function createCollection($collectionName, array $options = []) public function createCollection($collectionName, array $options = [])
{ {
if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
}
$operation = new CreateCollection($this->databaseName, $collectionName, $options); $operation = new CreateCollection($this->databaseName, $collectionName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
......
...@@ -51,6 +51,9 @@ class CreateCollection implements Executable ...@@ -51,6 +51,9 @@ class CreateCollection implements Executable
* *
* * storageEngine (document): Storage engine options. * * 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. * * validationAction (string): Validation action.
* *
* * validationLevel (string): Validation level. * * validationLevel (string): Validation level.
...@@ -98,6 +101,10 @@ class CreateCollection implements Executable ...@@ -98,6 +101,10 @@ class CreateCollection implements Executable
throw InvalidArgumentException::invalidType('"storageEngine" option', $options['storageEngine'], 'array or object'); 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'])) { if (isset($options['validationAction']) && ! is_string($options['validationAction'])) {
throw InvalidArgumentException::invalidType('"validationAction" option', $options['validationAction'], 'string'); throw InvalidArgumentException::invalidType('"validationAction" option', $options['validationAction'], 'string');
} }
...@@ -126,6 +133,10 @@ class CreateCollection implements Executable ...@@ -126,6 +133,10 @@ class CreateCollection implements Executable
{ {
$cursor = $server->executeCommand($this->databaseName, $this->createCommand()); $cursor = $server->executeCommand($this->databaseName, $this->createCommand());
if (isset($this->options['typeMap'])) {
$cursor->setTypeMap($this->options['typeMap']);
}
return current($cursor->toArray()); return current($cursor->toArray());
} }
......
...@@ -51,6 +51,10 @@ class CreateCollectionTest extends TestCase ...@@ -51,6 +51,10 @@ class CreateCollectionTest extends TestCase
$options[][] = ['storageEngine' => $value]; $options[][] = ['storageEngine' => $value];
} }
foreach ($this->getInvalidArrayValues() as $value) {
$options[][] = ['typeMap' => $value];
}
foreach ($this->getInvalidStringValues() as $value) { foreach ($this->getInvalidStringValues() as $value) {
$options[][] = ['validationAction' => $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