Skip to content

Commit 6ee316a

Browse files
committed
Merge pull request #103
2 parents f8362dc + 3cd6994 commit 6ee316a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/Database.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ public function command($command, array $options = [])
170170
*/
171171
public function createCollection($collectionName, array $options = [])
172172
{
173+
if ( ! isset($options['typeMap'])) {
174+
$options['typeMap'] = $this->typeMap;
175+
}
176+
173177
$operation = new CreateCollection($this->databaseName, $collectionName, $options);
174178
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
175179

src/Operation/CreateCollection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class CreateCollection implements Executable
5151
*
5252
* * storageEngine (document): Storage engine options.
5353
*
54+
* * typeMap (array): Type map for BSON deserialization. This will only be
55+
* used for the returned command result document.
56+
*
5457
* * validationAction (string): Validation action.
5558
*
5659
* * validationLevel (string): Validation level.
@@ -98,6 +101,10 @@ public function __construct($databaseName, $collectionName, array $options = [])
98101
throw InvalidArgumentException::invalidType('"storageEngine" option', $options['storageEngine'], 'array or object');
99102
}
100103

104+
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
105+
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
106+
}
107+
101108
if (isset($options['validationAction']) && ! is_string($options['validationAction'])) {
102109
throw InvalidArgumentException::invalidType('"validationAction" option', $options['validationAction'], 'string');
103110
}
@@ -126,6 +133,10 @@ public function execute(Server $server)
126133
{
127134
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
128135

136+
if (isset($this->options['typeMap'])) {
137+
$cursor->setTypeMap($this->options['typeMap']);
138+
}
139+
129140
return current($cursor->toArray());
130141
}
131142

tests/Operation/CreateCollectionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function provideInvalidConstructorOptions()
5151
$options[][] = ['storageEngine' => $value];
5252
}
5353

54+
foreach ($this->getInvalidArrayValues() as $value) {
55+
$options[][] = ['typeMap' => $value];
56+
}
57+
5458
foreach ($this->getInvalidStringValues() as $value) {
5559
$options[][] = ['validationAction' => $value];
5660
}

0 commit comments

Comments
 (0)