Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
6ee316a8
Commit
6ee316a8
authored
Jan 21, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #103
parents
f8362dc3
3cd69949
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
0 deletions
+19
-0
Database.php
src/Database.php
+4
-0
CreateCollection.php
src/Operation/CreateCollection.php
+11
-0
CreateCollectionTest.php
tests/Operation/CreateCollectionTest.php
+4
-0
No files found.
src/Database.php
View file @
6ee316a8
...
@@ -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
));
...
...
src/Operation/CreateCollection.php
View file @
6ee316a8
...
@@ -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
());
}
}
...
...
tests/Operation/CreateCollectionTest.php
View file @
6ee316a8
...
@@ -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
];
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment