class LoggableDatabase extends Database implements Loggable (View source)

Wrapper for the MongoDB class with logging functionality.

Properties

protected Connection $connection The Connection instance to which this database belongs. from Database
protected EventManager $eventManager The EventManager used to dispatch events. from Database
protected MongoDB $mongoDB The MongoDB instance being wrapped. from Database
protected integer $numRetries Number of times to retry queries. from Database
protected callable $loggerCallable The logger callable.

Methods

__construct(Connection $connection, MongoDB $mongoDB, EventManager $evm, boolean|integer $numRetries, callable $loggerCallable)

Constructor.

array
authenticate(string $username, string $password)

No description

array
command(array $data, array $options = [], string $hash = null)

No description

createCollection(string $name, boolean|array $cappedOrOptions = false, integer $size = 0, integer $max = 0)

No description

array
createDBRef(string $collection, mixed $a)

Wrapper method for MongoDB::createDBRef().

from Database
array
drop()

No description

array
dropCollection(string $coll)

Wrapper method for MongoDB::dropCollection().

from Database
array
execute($code, array $args = [])

No description

array
forceError() deprecated

Wrapper method for MongoDB::forceError().

from Database
getConnection()

Return the connection for this database.

from Database
array|null
getDBRef(array $ref)

No description

getGridFS(string $prefix = 'fs')

Wrapper method for MongoDB::getGridFS().

from Database
MongoDB
getMongoDB()

Return the MongoDB instance being wrapped.

from Database
string
getName()

Return the name of this database.

from Database
integer
getProfilingLevel()

Wrapper method for MongoDB::getProfilingLevel().

from Database
integer
setProfilingLevel(integer $level)

Wrapper method for MongoDB::setProfilingLevel().

from Database
array
getReadPreference()

Wrapper method for MongoDB::getReadPreference().

from Database
boolean
setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoDB::setReadPreference().

from Database
boolean
getSlaveOkay()

Get whether secondary read queries are allowed for this database.

from Database
boolean
setSlaveOkay(boolean $ok = true)

Set whether secondary read queries are allowed for this database.

from Database
array
lastError()

Wrapper method for MongoDB::lastError().

from Database
array
listCollections()

Wrapper method for MongoDB::listCollections().

from Database
array
prevError() deprecated

Wrapper method for MongoDB::prevError().

from Database
array
repair(boolean $preserveClonedFiles = false, boolean $backupOriginalFiles = false)

Wrapper method for MongoDB::repair().

from Database
array
resetError() deprecated

Wrapper method for MongoDB::resetError().

from Database
selectCollection(string $name)

Wrapper method for MongoDB::selectCollection().

from Database
MongoCollection
__get(string $name)

Wrapper method for MongoDB::__get().

from Database
string
__toString()

Wrapper method for MongoDB::__toString().

from Database
array|null
doGetDBRef(array $reference)

Resolves a database reference.

from Database
doCreateCollection(string $name, array $options)

Creates a collection.

from Database
doGetGridFS(string $prefix)

No description

doSelectCollection(string $name)

Return a new LoggableCollection instance.

mixed
retry(Closure $retry)

Conditionally retry a closure if it yields an exception.

from Database
array
convertSocketTimeout(array $options)

Convert "timeout" write option to "socketTimeoutMS" for driver version 1.5.0+.

from Database
log(array $log)

Log something using the configured logger callable.

Details

__construct(Connection $connection, MongoDB $mongoDB, EventManager $evm, boolean|integer $numRetries, callable $loggerCallable)

Constructor.

Parameters

Connection $connection Connection to which this database belongs
MongoDB $mongoDB MongoDB instance being wrapped
EventManager $evm EventManager instance
boolean|integer $numRetries Number of times to retry queries
callable $loggerCallable The logger callable

array authenticate(string $username, string $password)

Parameters

string $username
string $password

Return Value

array

See also

Database::authenticate

array command(array $data, array $options = [], string $hash = null)

Parameters

array $data
array $options Client-side options (e.g. socket timeout)
string $hash Optional reference argument to collect the server hash for command cursors (for driver 1.5+ only)

Return Value

array

See also

Database::command

Collection createCollection(string $name, boolean|array $cappedOrOptions = false, integer $size = 0, integer $max = 0)

Parameters

string $name Collection name
boolean|array $cappedOrOptions Capped collection indicator or an options array (for driver 1.4+)
integer $size Storage size for fixed collections (ignored if options array is used)
integer $max Max documents for fixed collections (ignored if options array is used)

Return Value

Collection

See also

Database::createCollection

array createDBRef(string $collection, mixed $a)

Wrapper method for MongoDB::createDBRef().

Parameters

string $collection
mixed $a

Return Value

array

See also

http://php.net/manual/en/mongodb.createdbref.php

array drop()

Return Value

array

See also

Database::drop

array dropCollection(string $coll)

Wrapper method for MongoDB::dropCollection().

Parameters

string $coll

Return Value

array

See also

http://php.net/manual/en/mongodb.dropcollection.php

array execute($code, array $args = [])

Parameters

$code
array $args

Return Value

array

See also

Database::execute

array forceError() deprecated

deprecated 1.1 Deprecated in driver; will be removed for 1.2

Wrapper method for MongoDB::forceError().

Connection getConnection()

Return the connection for this database.

Return Value

Connection

array|null getDBRef(array $ref)

Parameters

array $ref

Return Value

array|null

See also

Database::getDBRef

GridFS getGridFS(string $prefix = 'fs')

Wrapper method for MongoDB::getGridFS().

This method will dispatch preGetGridFS and postGetGridFS events.

Parameters

string $prefix

Return Value

GridFS

See also

http://php.net/manual/en/mongodb.getgridfs.php

MongoDB getMongoDB()

Return the MongoDB instance being wrapped.

Return Value

MongoDB

string getName()

Return the name of this database.

Return Value

string

integer getProfilingLevel()

Wrapper method for MongoDB::getProfilingLevel().

integer setProfilingLevel(integer $level)

Wrapper method for MongoDB::setProfilingLevel().

Parameters

integer $level

Return Value

integer

See also

http://php.net/manual/en/mongodb.setprofilinglevel.php

array getReadPreference()

Wrapper method for MongoDB::getReadPreference().

For driver versions between 1.3.0 and 1.3.3, the return value will be converted for consistency with {@link Database::setReadPreference()}.

boolean setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoDB::setReadPreference().

Parameters

string $readPreference
array $tags

Return Value

boolean

See also

http://php.net/manual/en/mongodb.setreadpreference.php

boolean getSlaveOkay()

Get whether secondary read queries are allowed for this database.

This method wraps getSlaveOkay() for driver versions before 1.3.0. For newer drivers, this method considers any read preference other than PRIMARY as a true "slaveOkay" value.

boolean setSlaveOkay(boolean $ok = true)

Set whether secondary read queries are allowed for this database.

This method wraps setSlaveOkay() for driver versions before 1.3.0. For newer drivers, this method wraps setReadPreference() and specifies SECONDARY_PREFERRED.

Parameters

boolean $ok

Return Value

boolean Previous slaveOk value

See also

http://php.net/manual/en/mongodb.setreadpreference.php
http://php.net/manual/en/mongodb.setslaveokay.php

array lastError()

Wrapper method for MongoDB::lastError().

array listCollections()

Wrapper method for MongoDB::listCollections().

array prevError() deprecated

deprecated 1.1 Deprecated in driver; will be removed for 1.2

Wrapper method for MongoDB::prevError().

array repair(boolean $preserveClonedFiles = false, boolean $backupOriginalFiles = false)

Wrapper method for MongoDB::repair().

Parameters

boolean $preserveClonedFiles
boolean $backupOriginalFiles

Return Value

array

See also

http://php.net/manual/en/mongodb.repair.php

array resetError() deprecated

deprecated 1.1 Deprecated in driver; will be removed for 1.2

Wrapper method for MongoDB::resetError().

Collection selectCollection(string $name)

Wrapper method for MongoDB::selectCollection().

This method will dispatch preSelectCollection and postSelectCollection events.

Parameters

string $name

Return Value

Collection

See also

http://php.net/manual/en/mongodb.selectcollection.php

MongoCollection __get(string $name)

Wrapper method for MongoDB::__get().

Parameters

string $name

Return Value

MongoCollection

See also

http://php.net/manual/en/mongodb.get.php

string __toString()

Wrapper method for MongoDB::__toString().

protected array|null doGetDBRef(array $reference)

Resolves a database reference.

Parameters

array $reference

Return Value

array|null

See also

Database::getDBRef

protected Collection doCreateCollection(string $name, array $options)

Creates a collection.

Parameters

string $name
array $options

Return Value

Collection

See also

Database::createCollection

protected GridFS doGetGridFS(string $prefix)

Parameters

string $prefix

Return Value

GridFS

See also

Database::doGetGridFS

protected Collection doSelectCollection(string $name)

Return a new LoggableCollection instance.

Parameters

string $name

Return Value

Collection

See also

Database::doSelectCollection

protected mixed retry(Closure $retry)

Conditionally retry a closure if it yields an exception.

If the closure does not return successfully within the configured number of retries, its first exception will be thrown.

This method should not be used for write operations.

Parameters

Closure $retry

Return Value

mixed

protected array convertSocketTimeout(array $options)

Convert "timeout" write option to "socketTimeoutMS" for driver version 1.5.0+.

Parameters

array $options

Return Value

array

log(array $log)

Log something using the configured logger callable.

Parameters

array $log

See also

Loggable::log