PHP Class Sokil\Mongo\Client

显示文件 Open project: sokil/php-mongo Class Usage Examples

Public Methods

Method Description
__construct ( string $dsn = null, array $options = null )
__get ( $name )
createPersistence ( ) : Sokil\Mongo\Persistence Create new persistence manager
debug ( $enabled = true ) Enable or disable debug mode
getCollection ( string $name ) : Collection Get collection from previously selected database by self::useDatabase()
getConnectOptions ( )
getConnections ( ) : array Get list of all active connections through this client
getCurrentDatabaseName ( ) : string Get name of current database
getDatabase ( string $name = null ) : Database Get database instance
getDbVersion ( ) : string
getDsn ( )
getLogger ( ) : Psr\Log\LoggerInterface
getMongoClient ( ) : MongoClient Get mongo connection instance
getReadPreference ( )
getVersion ( ) : string
getWriteConcern ( ) : string | integer Get currently active write concern on connection level
hasLogger ( ) : boolean Check if logger defined
isDebugEnabled ( ) Check state of debug mode
map ( array $mapping ) : Client Map database and collection name to class.
readNearest ( array $tags = null )
readPrimaryOnly ( )
readPrimaryPreferred ( array $tags = null )
readSecondaryOnly ( array $tags = null )
readSecondaryPreferred ( array $tags = null )
removeLogger ( ) : Client Remove logger
setConnectOptions ( array $options ) : Client Set connect options
setCredentials ( type $username, type $password ) : Client Set credentials to auth on db, specified in connect options or dsn.
setDsn ( $dsn )
setLogger ( Psr\Log\LoggerInterface $logger )
setMajorityWriteConcern ( integer $timeout = 10000 ) : Client Define majority write concern on whole requests
setMongoClient ( MongoClient $client ) : Client Set mongo's client
setUnacknowledgedWriteConcern ( integer $timeout = 10000 ) : Client Define unacknowledged write concern on whole requests
setWriteConcern ( string | integer $w, integer $timeout = 10000 ) : Client Define write concern on whole requests
useDatabase ( string $name ) : Client Select database

Method Details

__construct() public method

public __construct ( string $dsn = null, array $options = null )
$dsn string Data Source Name
$options array

__get() public method

public __get ( $name )

createPersistence() public method

Create new persistence manager
public createPersistence ( ) : Sokil\Mongo\Persistence
return Sokil\Mongo\Persistence

debug() public method

Enable or disable debug mode
public debug ( $enabled = true )

getCollection() public method

Get collection from previously selected database by self::useDatabase()
public getCollection ( string $name ) : Collection
$name string
return Collection

getConnectOptions() public method

public getConnectOptions ( )

getConnections() public method

Get list of all active connections through this client
public getConnections ( ) : array
return array

getCurrentDatabaseName() public method

Get name of current database
public getCurrentDatabaseName ( ) : string
return string

getDatabase() public method

Get database instance
public getDatabase ( string $name = null ) : Database
$name string database name
return Database

getDbVersion() public method

public getDbVersion ( ) : string
return string version of mongo database

getDsn() public method

public getDsn ( )

getLogger() public method

public getLogger ( ) : Psr\Log\LoggerInterface
return Psr\Log\LoggerInterface

getMongoClient() public method

Get mongo connection instance
public getMongoClient ( ) : MongoClient
return MongoClient

getReadPreference() public method

public getReadPreference ( )

getVersion() public method

public getVersion ( ) : string
return string Version of PHP driver

getWriteConcern() public method

Get currently active write concern on connection level
public getWriteConcern ( ) : string | integer
return string | integer

hasLogger() public method

Check if logger defined
public hasLogger ( ) : boolean
return boolean

isDebugEnabled() public method

Check state of debug mode
public isDebugEnabled ( )

map() public method

Collection name -> array definition: ['acmeDatabaseName' => ['acmeCollectionName' => ['class' => '\Acme\Collection\SomeCollectionClass']]] Collection name -> collection class name (deprecated: use definition array): ['acmeDatabaseName' => ['acmeCollectionName' => '\Acme\Collection\SomeCollectionClass']] Collection's class namespace (deprecated: use definition array): ['acmeDatabaseName' => '\Acme\Collection']
public map ( array $mapping ) : Client
$mapping array classpath or class prefix
return Client

readNearest() public method

public readNearest ( array $tags = null )
$tags array

readPrimaryOnly() public method

public readPrimaryOnly ( )

readPrimaryPreferred() public method

public readPrimaryPreferred ( array $tags = null )
$tags array

readSecondaryOnly() public method

public readSecondaryOnly ( array $tags = null )
$tags array

readSecondaryPreferred() public method

public readSecondaryPreferred ( array $tags = null )
$tags array

removeLogger() public method

Remove logger
public removeLogger ( ) : Client
return Client

setConnectOptions() public method

Set connect options
public setConnectOptions ( array $options ) : Client
$options array
return Client

setCredentials() public method

If not specified - auth on admin db
public setCredentials ( type $username, type $password ) : Client
$username type
$password type
return Client

setDsn() public method

public setDsn ( $dsn )

setLogger() public method

public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface

setMajorityWriteConcern() public method

Define majority write concern on whole requests
public setMajorityWriteConcern ( integer $timeout = 10000 ) : Client
$timeout integer timeout in milliseconds
return Client

setMongoClient() public method

Set mongo's client
public setMongoClient ( MongoClient $client ) : Client
$client MongoClient
return Client

setUnacknowledgedWriteConcern() public method

Define unacknowledged write concern on whole requests
public setUnacknowledgedWriteConcern ( integer $timeout = 10000 ) : Client
$timeout integer timeout in milliseconds
return Client

setWriteConcern() public method

Define write concern on whole requests
public setWriteConcern ( string | integer $w, integer $timeout = 10000 ) : Client
$w string | integer write concern
$timeout integer timeout in milliseconds
return Client

useDatabase() public method

Select database
public useDatabase ( string $name ) : Client
$name string
return Client