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
9d7f8e64
Commit
9d7f8e64
authored
Dec 26, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74
Please enter a commit message to explain why this merge is necessary,
parents
28e0574f
329ed9ce
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
CreateCollection.php
src/Operation/CreateCollection.php
+26
-3
CreateCollectionTest.php
tests/Operation/CreateCollectionTest.php
+12
-0
No files found.
src/Operation/CreateCollection.php
View file @
9d7f8e64
...
...
@@ -52,7 +52,14 @@ class CreateCollection implements Executable
*
* * storageEngine (document): Storage engine options.
*
* * validationAction (string): Validation action.
*
* * validationLevel (string): Validation level.
*
* * validator (document): Validation rules or expressions.
*
* @see http://source.wiredtiger.com/2.4.1/struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb
* @see https://docs.mongodb.org/manual/core/document-validation/
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param array $options Command options
...
...
@@ -92,6 +99,18 @@ class CreateCollection implements Executable
throw
new
InvalidArgumentTypeException
(
'"storageEngine" option'
,
$options
[
'storageEngine'
],
'array or object'
);
}
if
(
isset
(
$options
[
'validationAction'
])
&&
!
is_string
(
$options
[
'validationAction'
]))
{
throw
new
InvalidArgumentTypeException
(
'"validationAction" option'
,
$options
[
'validationAction'
],
'string'
);
}
if
(
isset
(
$options
[
'validationLevel'
])
&&
!
is_string
(
$options
[
'validationLevel'
]))
{
throw
new
InvalidArgumentTypeException
(
'"validationLevel" option'
,
$options
[
'validationLevel'
],
'string'
);
}
if
(
isset
(
$options
[
'validator'
])
&&
!
is_array
(
$options
[
'validator'
])
&&
!
is_object
(
$options
[
'validator'
]))
{
throw
new
InvalidArgumentTypeException
(
'"validator" option'
,
$options
[
'validator'
],
'array or object'
);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
options
=
$options
;
...
...
@@ -120,20 +139,24 @@ class CreateCollection implements Executable
{
$cmd
=
[
'create'
=>
$this
->
collectionName
];
foreach
([
'autoIndexId'
,
'capped'
,
'flags'
,
'max'
,
'maxTimeMS'
,
'size'
]
as
$option
)
{
foreach
([
'autoIndexId'
,
'capped'
,
'flags'
,
'max'
,
'maxTimeMS'
,
'size'
,
'validationAction'
,
'validationLevel'
]
as
$option
)
{
if
(
isset
(
$this
->
options
[
$option
]))
{
$cmd
[
$option
]
=
$this
->
options
[
$option
];
}
}
if
(
!
empty
(
$this
->
options
[
'indexOptionDefaults'
]))
{
if
(
isset
(
$this
->
options
[
'indexOptionDefaults'
]))
{
$cmd
[
'indexOptionDefaults'
]
=
(
object
)
$this
->
options
[
'indexOptionDefaults'
];
}
if
(
!
empty
(
$this
->
options
[
'storageEngine'
]))
{
if
(
isset
(
$this
->
options
[
'storageEngine'
]))
{
$cmd
[
'storageEngine'
]
=
(
object
)
$this
->
options
[
'storageEngine'
];
}
if
(
isset
(
$this
->
options
[
'validator'
]))
{
$cmd
[
'validator'
]
=
(
object
)
$this
->
options
[
'validator'
];
}
return
new
Command
(
$cmd
);
}
}
tests/Operation/CreateCollectionTest.php
View file @
9d7f8e64
...
...
@@ -51,6 +51,18 @@ class CreateCollectionTest extends TestCase
$options
[][]
=
[
'storageEngine'
=>
$value
];
}
foreach
(
$this
->
getInvalidStringValues
()
as
$value
)
{
$options
[][]
=
[
'validationAction'
=>
$value
];
}
foreach
(
$this
->
getInvalidStringValues
()
as
$value
)
{
$options
[][]
=
[
'validationLevel'
=>
$value
];
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
[
'validator'
=>
$value
];
}
return
$options
;
}
}
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