Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Functions that are not part of a class:

all_servers_support_write_stage_on_secondary(array $servers)   X-Ref
Check whether all servers support executing a write stage on a secondary.

param: Server[] $servers

apply_type_map_to_document($document, array $typeMap)   X-Ref
Applies a type map to a document.

This function is used by operations where it is not possible to apply a type
map to the cursor directly because the root document is a command response
(e.g. findAndModify).

param: array|object $document Document to which the type map will be applied
param: array        $typeMap  Type map for BSON deserialization.
return: array|object

generate_index_name($document)   X-Ref
Generate an index name from a key specification.

param: array|object $document Document containing fields mapped to values,

get_encrypted_fields_from_driver(string $databaseName, string $collectionName, Manager $manager)   X-Ref
Return a collection's encryptedFields from the encryptedFieldsMap
autoEncryption driver option (if available).

return: array|object|null

get_encrypted_fields_from_server(string $databaseName, string $collectionName, Manager $manager, Server $server)   X-Ref
Return a collection's encryptedFields option from the server (if any).

return: array|object|null

is_first_key_operator($document)   X-Ref
Return whether the first key in the document starts with a "$" character.

This is used for differentiating update and replacement documents.

param: array|object $document Update or replacement document

is_pipeline($pipeline)   X-Ref
Returns whether an update specification is a valid aggregation pipeline.

param: mixed $pipeline

is_in_transaction(array $options)   X-Ref
Returns whether we are currently in a transaction.

param: array $options Command options

is_last_pipeline_operator_write(array $pipeline)   X-Ref
Return whether the aggregation pipeline ends with an $out or $merge operator.

This is used for determining whether the aggregation pipeline must be
executed against a primary server.

param: array $pipeline List of pipeline operations

is_mapreduce_output_inline($out)   X-Ref
Return whether the "out" option for a mapReduce operation is "inline".

This is used to determine if a mapReduce command requires a primary.

param: string|array|object $out Output specification

is_write_concern_acknowledged(WriteConcern $writeConcern)   X-Ref
Return whether the write concern is acknowledged.

This function is similar to mongoc_write_concern_is_acknowledged but does not
check the fsync option since that was never supported in the PHP driver.


server_supports_feature(Server $server, int $feature)   X-Ref
Return whether the server supports a particular feature.

param: Server  $server  Server to check
param: integer $feature Feature constant (i.e. wire protocol version)

is_string_array($input)   X-Ref
Return whether the input is an array of strings.

param: mixed $input

recursive_copy($element)   X-Ref
Performs a deep copy of a value.

This function will clone objects and recursively copy values within arrays.

param: mixed $element Value to be copied
return: mixed

create_field_path_type_map(array $typeMap, string $fieldPath)   X-Ref
Creates a type map to apply to a field type

This is used in the Aggregate, Distinct, and FindAndModify operations to
apply the root-level type map to the document that will be returned. It also
replaces the root type with object for consistency within these operations

An existing type map for the given field path will not be overwritten

param: array  $typeMap   The existing typeMap
param: string $fieldPath The field path to apply the root type to

with_transaction(Session $session, callable $callback, array $transactionOptions = [])   X-Ref
Execute a callback within a transaction in the given session

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.

param: Session  $session            A session object as retrieved by Client::startSession
param: callable $callback           A callback that will be invoked within the transaction
param: array    $transactionOptions Additional options that are passed to Session::startTransaction

extract_session_from_options(array $options)   X-Ref
Returns the session option if it is set and valid.


extract_read_preference_from_options(array $options)   X-Ref
Returns the readPreference option if it is set and valid.


select_server(Manager $manager, array $options)   X-Ref
Performs server selection, respecting the readPreference and session options
(if given)


select_server_for_aggregate_write_stage(Manager $manager, array &$options)   X-Ref
Performs server selection for an aggregate operation with a write stage. The
$options parameter may be modified by reference if a primary read preference
must be forced due to the existence of pre-5.0 servers in the topology.