Documentation

functions.php

Table of Contents

Functions

add_logger()  : void
Registers a PSR-3 logger to receive log messages from the driver/library.
remove_logger()  : void
Unregisters a PSR-3 logger.
object()  : stdClass
Create a new stdClass instance with the provided properties.
with_transaction()  : void
Execute a callback within a transaction in the given session

Functions

add_logger()

Registers a PSR-3 logger to receive log messages from the driver/library.

add_logger(LoggerInterface $logger) : void

Calling this method again with a logger that has already been added will have no effect.

Parameters
$logger : LoggerInterface

remove_logger()

Unregisters a PSR-3 logger.

remove_logger(LoggerInterface $logger) : void

Calling this method with a logger that has not been added will have no effect.

Parameters
$logger : LoggerInterface

object()

Create a new stdClass instance with the provided properties.

object(mixed ...$values) : stdClass

Use named arguments to specify the property names. object( property1: value1, property2: value2 )

If property names contain a dot or a dollar characters, use array unpacking syntax. object( ...[ 'author.name' => 1, 'array.$' => 1 ] )

Parameters
$values : mixed
Tags
psalm-suppress

MoreSpecificReturnType

psalm-suppress

LessSpecificReturnStatement

Return values
stdClass

with_transaction()

Execute a callback within a transaction in the given session

with_transaction(Session $session, callable $callback[, array<string|int, mixed> $transactionOptions = [] ]) : void

This helper takes care of retrying the commit operation or the entire transaction if an error occurs.

If the commit fails because of an UnknownTransactionCommitResult error, the commit is retried without re-invoking the callback. If the commit fails because of a TransientTransactionError, the entire transaction will be retried. In this case, the callback will be invoked again. It is important that the logic inside the callback is idempotent.

In case of failures, the commit or transaction are retried until 120 seconds from the initial call have elapsed. After that, no retries will happen and the helper will throw the last exception received from the driver.

Parameters
$session : Session

A session object as retrieved by Client::startSession

$callback : callable

A callback that will be invoked within the transaction

$transactionOptions : array<string|int, mixed> = []

Additional options that are passed to Session::startTransaction

Tags
see
Client::startSession()
see
Session::startTransaction()

for supported transaction options

throws
RuntimeException

for driver errors while committing the transaction

throws
Exception

for any other errors, including those thrown in the callback


        
On this page

Search results