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
694c2117
Commit
694c2117
authored
Sep 02, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27
parents
ced71457
e223a19c
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
11 additions
and
45 deletions
+11
-45
Client.php
src/Client.php
+4
-8
Aggregate.php
src/Operation/Aggregate.php
+0
-4
Count.php
src/Operation/Count.php
+5
-6
CreateCollection.php
src/Operation/CreateCollection.php
+0
-4
CreateIndexes.php
src/Operation/CreateIndexes.php
+2
-3
Distinct.php
src/Operation/Distinct.php
+0
-4
DropCollection.php
src/Operation/DropCollection.php
+0
-4
DropDatabase.php
src/Operation/DropDatabase.php
+0
-4
DropIndexes.php
src/Operation/DropIndexes.php
+0
-4
FindAndModify.php
src/Operation/FindAndModify.php
+0
-4
No files found.
src/Client.php
View file @
694c2117
...
@@ -14,8 +14,6 @@ use MongoDB\Operation\ListDatabases;
...
@@ -14,8 +14,6 @@ use MongoDB\Operation\ListDatabases;
class
Client
class
Client
{
{
private
$manager
;
private
$manager
;
private
$readPreference
;
private
$writeConcern
;
/**
/**
* Constructs a new Client instance.
* Constructs a new Client instance.
...
@@ -77,9 +75,8 @@ class Client
...
@@ -77,9 +75,8 @@ class Client
public
function
selectCollection
(
$databaseName
,
$collectionName
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
public
function
selectCollection
(
$databaseName
,
$collectionName
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
{
{
$namespace
=
$databaseName
.
'.'
.
$collectionName
;
$namespace
=
$databaseName
.
'.'
.
$collectionName
;
// TODO: inherit from Manager options once PHPC-196 is implemented
$writeConcern
=
$writeConcern
?:
$this
->
manager
->
getWriteConcern
();
$writeConcern
=
$writeConcern
?:
$this
->
writeConcern
;
$readPreference
=
$readPreference
?:
$this
->
manager
->
getReadPreference
();
$readPreference
=
$readPreference
?:
$this
->
readPreference
;
return
new
Collection
(
$this
->
manager
,
$namespace
,
$writeConcern
,
$readPreference
);
return
new
Collection
(
$this
->
manager
,
$namespace
,
$writeConcern
,
$readPreference
);
}
}
...
@@ -97,9 +94,8 @@ class Client
...
@@ -97,9 +94,8 @@ class Client
*/
*/
public
function
selectDatabase
(
$databaseName
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
public
function
selectDatabase
(
$databaseName
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
{
{
// TODO: inherit from Manager options once PHPC-196 is implemented
$writeConcern
=
$writeConcern
?:
$this
->
manager
->
getWriteConcern
();
$writeConcern
=
$writeConcern
?:
$this
->
writeConcern
;
$readPreference
=
$readPreference
?:
$this
->
manager
->
getReadPreference
();
$readPreference
=
$readPreference
?:
$this
->
readPreference
;
return
new
Database
(
$this
->
manager
,
$databaseName
,
$writeConcern
,
$readPreference
);
return
new
Database
(
$this
->
manager
,
$databaseName
,
$writeConcern
,
$readPreference
);
}
}
...
...
src/Operation/Aggregate.php
View file @
694c2117
...
@@ -122,12 +122,8 @@ class Aggregate implements Executable
...
@@ -122,12 +122,8 @@ class Aggregate implements Executable
return
$cursor
;
return
$cursor
;
}
}
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
...
...
src/Operation/Count.php
View file @
694c2117
...
@@ -85,19 +85,18 @@ class Count implements Executable
...
@@ -85,19 +85,18 @@ class Count implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
// Older server versions may return a float
// Older server versions may return a float
if
(
!
isset
(
$result
[
'n'
])
||
!
(
is_integer
(
$result
[
'n'
])
||
is_float
(
$result
[
'n'
]
)))
{
if
(
!
isset
(
$result
->
n
)
||
!
(
is_integer
(
$result
->
n
)
||
is_float
(
$result
->
n
)))
{
throw
new
UnexpectedValueException
(
'count command did not return a
n
"n" value'
);
throw
new
UnexpectedValueException
(
'count command did not return a
numeric
"n" value'
);
}
}
return
(
integer
)
$result
[
'n'
]
;
return
(
integer
)
$result
->
n
;
}
}
/**
/**
...
...
src/Operation/CreateCollection.php
View file @
694c2117
...
@@ -102,12 +102,8 @@ class CreateCollection implements Executable
...
@@ -102,12 +102,8 @@ class CreateCollection implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
...
...
src/Operation/CreateIndexes.php
View file @
694c2117
...
@@ -91,11 +91,10 @@ class CreateIndexes implements Executable
...
@@ -91,11 +91,10 @@ class CreateIndexes implements Executable
));
));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
$cursor
->
setTypeMap
(
array
(
'root'
=>
'array'
,
'document'
=>
'array'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
}
}
...
...
src/Operation/Distinct.php
View file @
694c2117
...
@@ -62,12 +62,8 @@ class Distinct implements Executable
...
@@ -62,12 +62,8 @@ class Distinct implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
...
...
src/Operation/DropCollection.php
View file @
694c2117
...
@@ -41,12 +41,8 @@ class DropCollection implements Executable
...
@@ -41,12 +41,8 @@ class DropCollection implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'drop'
=>
$this
->
collectionName
)));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'drop'
=>
$this
->
collectionName
)));
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
...
...
src/Operation/DropDatabase.php
View file @
694c2117
...
@@ -39,12 +39,8 @@ class DropDatabase implements Executable
...
@@ -39,12 +39,8 @@ class DropDatabase implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'dropDatabase'
=>
1
)));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'dropDatabase'
=>
1
)));
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
...
...
src/Operation/DropIndexes.php
View file @
694c2117
...
@@ -56,12 +56,8 @@ class DropIndexes implements Executable
...
@@ -56,12 +56,8 @@ class DropIndexes implements Executable
);
);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
...
...
src/Operation/FindAndModify.php
View file @
694c2117
...
@@ -118,12 +118,8 @@ class FindAndModify implements Executable
...
@@ -118,12 +118,8 @@ class FindAndModify implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
->
setTypeMap
(
array
(
'document'
=>
'stdClass'
));
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
// TODO: Remove this once PHPC-318 is implemented
is_array
(
$result
)
and
$result
=
(
object
)
$result
;
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
...
...
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