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
0c8b44f5
Commit
0c8b44f5
authored
Sep 03, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate Aggregation $pipeline before $options
parent
913c2a39
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
Aggregate.php
src/Operation/Aggregate.php
+18
-14
No files found.
src/Operation/Aggregate.php
View file @
0c8b44f5
...
...
@@ -59,6 +59,24 @@ class Aggregate implements Executable
*/
public
function
__construct
(
$databaseName
,
$collectionName
,
array
$pipeline
,
array
$options
=
array
())
{
if
(
empty
(
$pipeline
))
{
throw
new
InvalidArgumentException
(
'$pipeline is empty'
);
}
$expectedIndex
=
0
;
foreach
(
$pipeline
as
$i
=>
$operation
)
{
if
(
$i
!==
$expectedIndex
)
{
throw
new
InvalidArgumentException
(
sprintf
(
'$pipeline is not a list (unexpected index: "%s")'
,
$i
));
}
if
(
!
is_array
(
$operation
)
&&
!
is_object
(
$operation
))
{
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$pipeline[%d]'
,
$i
),
$operation
,
'array or object'
);
}
$expectedIndex
+=
1
;
}
$options
+=
array
(
'allowDiskUse'
=>
false
,
'useCursor'
=>
true
,
...
...
@@ -84,20 +102,6 @@ class Aggregate implements Executable
throw
new
InvalidArgumentException
(
'"batchSize" option should not be used if "useCursor" is false'
);
}
$expectedIndex
=
0
;
foreach
(
$pipeline
as
$i
=>
$op
)
{
if
(
$i
!==
$expectedIndex
)
{
throw
new
InvalidArgumentException
(
sprintf
(
'$pipeline is not a list (unexpected index: "%s")'
,
$i
));
}
if
(
!
is_array
(
$op
)
&&
!
is_object
(
$op
))
{
throw
new
InvalidArgumentTypeException
(
sprintf
(
'$pipeline[%d]'
,
$i
),
$op
,
'array or object'
);
}
$expectedIndex
+=
1
;
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
pipeline
=
$pipeline
;
...
...
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