PHP Class Doctrine\MongoDB\Connection

Since: 1.0
Author: Jonathan H. Wage ([email protected])
Datei anzeigen Open project: doctrine/mongodb Class Usage Examples

Protected Properties

Property Type Description
$config Doctrine\MongoDB\Configuration The Configuration for this connection.
$driverOptions array Driver options used to construct the MongoClient instance (optional).
$eventManager Doctrine\Common\EventManager The EventManager used to dispatch events.
$mongoClient MongoClient The PHP MongoClient instance being wrapped.
$options array Options used to construct the MongoClient instance (optional).
$server string Server string used to construct the MongoClient instance (optional).

Public Methods

Method Description
__construct ( string | MongoClient $server = null, array $options = [], Doctrine\MongoDB\Configuration $config = null, Doctrine\Common\EventManager $evm = null, array $driverOptions = [] ) Constructor.
__get ( string $database ) : MongoDB Wrapper method for MongoClient::__get().
__toString ( ) : string Wrapper method for MongoClient::__toString().
close ( ) : boolean Wrapper method for MongoClient::close().
connect ( ) : boolean Wrapper method for MongoClient::connect().
dropDatabase ( string $database ) : array Wrapper method for MongoClient::dropDB().
getConfiguration ( ) : Doctrine\MongoDB\Configuration Get the Configuration used by this Connection.
getEventManager ( ) : Doctrine\Common\EventManager Get the EventManager used by this Connection.
getMongo ( ) : MongoClient Get the MongoClient instance being wrapped.
getMongoClient ( ) : MongoClient Get the MongoClient instance being wrapped.
getReadPreference ( ) : array Wrapper method for MongoClient::getReadPreference().
getServer ( ) : string | null Get the server string.
getStatus ( ) : string Gets the $status property of the wrapped MongoClient instance.
initialize ( ) Construct the wrapped MongoClient instance if necessary.
isConnected ( ) : boolean Checks whether the connection is initialized and connected.
listDatabases ( ) : array Wrapper method for MongoClient::listDBs().
log ( array $log ) Log something using the configured logger callable (if available).
selectCollection ( string $db, string $collection ) : Doctrine\MongoDB\Collection Wrapper method for MongoClient::selectCollection().
selectDatabase ( string $name ) : Doctrine\MongoDB\Database Wrapper method for MongoClient::selectDatabase().
setMongo ( MongoClient $mongoClient ) Set the MongoClient instance to wrap.
setReadPreference ( string $readPreference, array $tags = null ) : boolean Wrapper method for MongoClient::setReadPreference().

Protected Methods

Method Description
convertConnectTimeout ( array $options ) : array Converts "timeout" MongoClient constructor option to "connectTimeoutMS" for driver versions 1.4.0+.
convertWriteTimeout ( array $options ) : array Converts "wTimeout" MongoClient constructor option to "wTimeoutMS" for driver versions 1.4.0+.
doSelectDatabase ( string $name ) : Doctrine\MongoDB\Database Return a new Database instance.
retry ( Closure $retry ) : mixed Conditionally retry a closure if it yields an exception.

Method Details

__construct() public method

If $server is an existing MongoClient instance, the $options parameter will not be used.
public __construct ( string | MongoClient $server = null, array $options = [], Doctrine\MongoDB\Configuration $config = null, Doctrine\Common\EventManager $evm = null, array $driverOptions = [] )
$server string | MongoClient Server string or MongoClient instance
$options array MongoClient constructor options
$config Doctrine\MongoDB\Configuration Configuration instance
$evm Doctrine\Common\EventManager EventManager instance
$driverOptions array MongoClient constructor options

__get() public method

Wrapper method for MongoClient::__get().
See also: http://php.net/manual/en/mongoclient.get.php
public __get ( string $database ) : MongoDB
$database string
return MongoDB

__toString() public method

Wrapper method for MongoClient::__toString().
See also: http://php.net/manual/en/mongoclient.tostring.php
public __toString ( ) : string
return string

close() public method

Wrapper method for MongoClient::close().
See also: http://php.net/manual/en/mongoclient.close.php
public close ( ) : boolean
return boolean

connect() public method

Wrapper method for MongoClient::connect().
See also: http://php.net/manual/en/mongoclient.connect.php
public connect ( ) : boolean
return boolean

convertConnectTimeout() protected method

Note: MongoClient actually allows case-insensitive option names, but we'll only process the canonical version here.
protected convertConnectTimeout ( array $options ) : array
$options array
return array

convertWriteTimeout() protected method

Note: MongoClient actually allows case-insensitive option names, but we'll only process the canonical version here.
protected convertWriteTimeout ( array $options ) : array
$options array
return array

doSelectDatabase() protected method

If a logger callable was defined, a LoggableDatabase will be returned.
See also: Connection::selectDatabase()
protected doSelectDatabase ( string $name ) : Doctrine\MongoDB\Database
$name string
return Doctrine\MongoDB\Database

dropDatabase() public method

This method will dispatch preDropDatabase and postDropDatabase events.
See also: http://php.net/manual/en/mongoclient.dropdb.php
public dropDatabase ( string $database ) : array
$database string
return array

getConfiguration() public method

Get the Configuration used by this Connection.
public getConfiguration ( ) : Doctrine\MongoDB\Configuration
return Doctrine\MongoDB\Configuration

getEventManager() public method

Get the EventManager used by this Connection.
public getEventManager ( ) : Doctrine\Common\EventManager
return Doctrine\Common\EventManager

getMongo() public method

Get the MongoClient instance being wrapped.
Deprecation: 1.1 Replaced by getMongoClient(); will be removed for 2.0
public getMongo ( ) : MongoClient
return MongoClient

getMongoClient() public method

Get the MongoClient instance being wrapped.
public getMongoClient ( ) : MongoClient
return MongoClient

getReadPreference() public method

For driver versions between 1.3.0 and 1.3.3, the return value will be converted for consistency with {@link Connection::setReadPreference()}.
See also: http://php.net/manual/en/mongoclient.getreadpreference.php
public getReadPreference ( ) : array
return array

getServer() public method

Get the server string.
public getServer ( ) : string | null
return string | null

getStatus() public method

Gets the $status property of the wrapped MongoClient instance.
Deprecation: 1.1 No longer used in driver; Will be removed for 1.2
public getStatus ( ) : string
return string

initialize() public method

This method will dispatch preConnect and postConnect events.
public initialize ( )

isConnected() public method

Checks whether the connection is initialized and connected.
public isConnected ( ) : boolean
return boolean

listDatabases() public method

Wrapper method for MongoClient::listDBs().
See also: http://php.net/manual/en/mongoclient.listdbs.php
public listDatabases ( ) : array
return array

log() public method

Log something using the configured logger callable (if available).
public log ( array $log )
$log array

retry() protected method

If the closure does not return successfully within the configured number of retries, its first exception will be thrown.
protected retry ( Closure $retry ) : mixed
$retry Closure
return mixed

selectCollection() public method

Wrapper method for MongoClient::selectCollection().
See also: http://php.net/manual/en/mongoclient.selectcollection.php
public selectCollection ( string $db, string $collection ) : Doctrine\MongoDB\Collection
$db string
$collection string
return Doctrine\MongoDB\Collection

selectDatabase() public method

This method will dispatch preSelectDatabase and postSelectDatabase events.
See also: http://php.net/manual/en/mongoclient.selectdatabase.php
public selectDatabase ( string $name ) : Doctrine\MongoDB\Database
$name string
return Doctrine\MongoDB\Database

setMongo() public method

Set the MongoClient instance to wrap.
Deprecation: 1.1 Will be removed for 2.0
public setMongo ( MongoClient $mongoClient )
$mongoClient MongoClient

setReadPreference() public method

Wrapper method for MongoClient::setReadPreference().
See also: http://php.net/manual/en/mongoclient.setreadpreference.php
public setReadPreference ( string $readPreference, array $tags = null ) : boolean
$readPreference string
$tags array
return boolean

Property Details

$config protected_oe property

The Configuration for this connection.
protected Configuration,Doctrine\MongoDB $config
return Doctrine\MongoDB\Configuration

$driverOptions protected_oe property

Driver options used to construct the MongoClient instance (optional).
protected array $driverOptions
return array

$eventManager protected_oe property

The EventManager used to dispatch events.
protected EventManager,Doctrine\Common $eventManager
return Doctrine\Common\EventManager

$mongoClient protected_oe property

The PHP MongoClient instance being wrapped.
protected MongoClient $mongoClient
return MongoClient

$options protected_oe property

Options used to construct the MongoClient instance (optional).
protected array $options
return array

$server protected_oe property

Server string used to construct the MongoClient instance (optional).
protected string $server
return string