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
cfdfcb12
Commit
cfdfcb12
authored
Feb 02, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-303: Implement MongoDB\Client::startSession()
parent
2036f03f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
0 deletions
+115
-0
apiargs-MongoDBClient-method-startSession-option.yaml
...des/apiargs-MongoDBClient-method-startSession-option.yaml
+12
-0
MongoDBClient.txt
docs/reference/class/MongoDBClient.txt
+1
-0
MongoDBClient-startSession.txt
docs/reference/method/MongoDBClient-startSession.txt
+82
-0
Client.php
src/Client.php
+12
-0
ClientFunctionalTest.php
tests/ClientFunctionalTest.php
+8
-0
No files found.
docs/includes/apiargs-MongoDBClient-method-startSession-option.yaml
0 → 100644
View file @
cfdfcb12
arg_name
:
option
name
:
causalConsistency
type
:
boolean
description
:
|
Enables or disables :ref:`causal consistency <causal-consistency>` for the
session. If true, each operation in the session will be causally ordered after
the previous read or write operation. Set to false to disable causal
consistency. Defaults to true.
interface
:
phpmethod
operation
:
~
optional
:
true
...
docs/reference/class/MongoDBClient.txt
View file @
cfdfcb12
...
@@ -39,3 +39,4 @@ Methods
...
@@ -39,3 +39,4 @@ Methods
/reference/method/MongoDBClient-listDatabases
/reference/method/MongoDBClient-listDatabases
/reference/method/MongoDBClient-selectCollection
/reference/method/MongoDBClient-selectCollection
/reference/method/MongoDBClient-selectDatabase
/reference/method/MongoDBClient-selectDatabase
/reference/method/MongoDBClient-startSession
docs/reference/method/MongoDBClient-startSession.txt
0 → 100644
View file @
cfdfcb12
===============================
MongoDB\\Client::startSession()
===============================
.. default-domain:: mongodb
.. versionadded:: 1.3
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\\Client::startSession()
Start a new client session for use with this client.
.. code-block:: php
function startSession(array $options = []): MongoDB\Driver\Session
The ``$options`` parameter supports the following options:
.. include:: /includes/apiargs/MongoDBClient-method-startSession-option.rst
Return Values
-------------
A :php:`MongoDB\Driver\Session <mongodb-driver-session>`
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-driver-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Example
-------
The following example starts a new session:
.. code-block:: php
<?php
$client = new MongoDB\Client;
$session = $client->startSession();
var_dump($session);
The output would then resemble::
object(MongoDB\Driver\Session)#2043 (4) {
["logicalSessionId"]=>
array(1) {
["id"]=>
object(MongoDB\BSON\Binary)#225 (2) {
["data"]=>
string(16) "................"
["type"]=>
int(4)
}
}
["clusterTime"]=>
NULL
["causalConsistency"]=>
bool(true)
["operationTime"]=>
NULL
}
See Also
--------
- :php:`MongoDB\\Driver\\Manager::startSession()
<manual/en/mongodb-driver-manager.startsession.php>`
- :ref:`Causal Consistency <causal-consistency>` in the MongoDB manual
src/Client.php
View file @
cfdfcb12
...
@@ -256,4 +256,16 @@ class Client
...
@@ -256,4 +256,16 @@ class Client
return
new
Database
(
$this
->
manager
,
$databaseName
,
$options
);
return
new
Database
(
$this
->
manager
,
$databaseName
,
$options
);
}
}
/**
* Start a new client session.
*
* @see http://php.net/manual/en/mongodb-driver-manager.startsession.php
* @param array $options Session options
* @return MongoDB\Driver\Session
*/
public
function
startSession
(
array
$options
=
[])
{
return
$this
->
manager
->
startSession
(
$options
);
}
}
}
tests/ClientFunctionalTest.php
View file @
cfdfcb12
...
@@ -97,4 +97,12 @@ class ClientFunctionalTest extends FunctionalTestCase
...
@@ -97,4 +97,12 @@ class ClientFunctionalTest extends FunctionalTestCase
call_user_func
(
$callback
,
$foundDatabase
);
call_user_func
(
$callback
,
$foundDatabase
);
}
}
}
}
public
function
testStartSession
()
{
if
(
version_compare
(
$this
->
getFeatureCompatibilityVersion
(),
'3.6'
,
'<'
))
{
$this
->
markTestSkipped
(
'startSession() is only supported on FCV 3.6 or higher'
);
}
$this
->
assertInstanceOf
(
'MongoDB\Driver\Session'
,
$this
->
client
->
startSession
());
}
}
}
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