PHP 클래스 lithium\data\source\MongoDb

Rather than operating on records and record sets, queries against MongoDB will return nested sets of Document objects. A Document's fields can contain both simple and complex data types (i.e. arrays) including other Document objects. After installing MongoDB, you can connect to it as follows: {{{//app/config/bootstrap/connections.php: Connections::add('default', array('type' => 'MongoDb', 'database' => 'myDb'));}}} By default, it will attempt to connect to a Mongo instance running on localhost on port 27017. See __construct() for details on the accepted configuration settings.
또한 보기: lithium\data\entity\Document
또한 보기: lithium\data\Connections::add()
또한 보기: lithium\data\source\MongoDb::__construct()
상속: extends lithium\data\Source
파일 보기 프로젝트 열기: unionofrad/lithium 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$connection object The MongoDB object instance.
$server object The Mongo class instance.

보호된 프로퍼티들

프로퍼티 타입 설명
$_autoConfig array List of configuration keys which will be automatically assigned to their corresponding protected class properties.
$_boolean array List of comparison operators to use when performing boolean logic in a query.
$_classes array Classes used by this class.
$_operators Map of typical SQL-like operators to their MongoDB equivalents.
$_schema Closure A closure or anonymous function which receives an instance of this class, a collection name and associated meta information, and returns an array defining the schema for an associated model, where the keys are field names, and the values are arrays defining the type information for each field. At a minimum, type arrays must contain a 'type' key. For more information on schema definitions, and an example schema callback implementation, see the $_schema property of the Model class.

공개 메소드들

메소드 설명
__call ( string $method, array $params ) : mixed A method dispatcher that allows direct calls to native methods in PHP's Mongo object. Read more here: http://php.net/manual/class.mongo.php
__construct ( array $config = [] ) : void Constructor.
__destruct ( ) : void Destructor. Ensures that the server connection is closed and resources are freed when the adapter instance is destroyed.
calculation ( string $type, mixed $query, array $options = [] ) : integer Executes calculation-related queries, such as those required for count.
conditions ( array $conditions, object $context ) : array Maps incoming conditions with their corresponding MongoDB-native operators.
configureClass ( string $class ) : Returns Configures a model class by overriding the default dependencies for 'set' and 'entity' , and sets the primary key to '_id', in keeping with Mongo's conventions.
connect ( ) : boolean Connects to the Mongo server. Matches up parameters from the constructor to create a Mongo database connection.
create ( string $query, array $options = [] ) : boolean Create new document
delete ( string $query, array $options = [] ) : boolean Delete document
describe ( mixed $collection, mixed $fields = [], array $meta = [] ) : array Gets the column 'schema' for a given MongoDB collection. Only returns a schema if the 'schema' configuration flag has been set in the constructor.
disconnect ( ) : boolean Disconnect from the Mongo server.
enabled ( string $feature = null ) : boolean With no parameter, checks to see if the mongo extension is installed. With a parameter, queries for a specific supported feature.
fields ( array $fields, object $context ) : array Return formatted identifiers for fields.
group ( string | array $group, object $context ) : array Formats group clauses for MongoDB.
limit ( mixed $limit, object $context ) : mixed Return formatted clause for limit.
name ( string $name ) : string Quotes identifiers.
order ( mixed $order, object $context ) : mixed Return formatted clause for order.
read ( string $query, array $options = [] ) : object Read from document
relationFieldName ( $type, $name ) : string Returns the field name of a relation name (camelBack).
relationship ( string $class, string $type, string $name, array $config = [] ) : array Document relationships.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.
schema ( $query, $resource = null, $context = null ) : array Normally used in cases where the query is a raw string (as opposed to a Query object), to database must determine the correct column names from the result resource. Not applicable to this data source.
sources ( string $class = null ) : array Returns the list of collections in the currently-connected database.
update ( string $query, array $options = [] ) : boolean Update document

보호된 메소드들

메소드 설명
_checkConnection ( )
_conditions ( array $conditions, string $model, object $schema, object $context ) : array Protected helper method used to format conditions.
_deleteFile ( $conditions, $options = [] )
_group ( $group, $args, $options )
_init ( ) : void Initializer. Adds operator handlers which will later allow to correctly cast any values.
_isMongoCode ( $conditions )
_ok ( $result ) : boolean Parse a MongoCollection::() response and return true on success.
_operators ( $field, $operators, $schema )
_saveFile ( $data )

메소드 상세

__call() 공개 메소드

For example (assuming this instance is stored in Connections as 'mongo'): Manually repairs a MongoDB instance Connections::get('mongo')->repairDB($db); // returns null
public __call ( string $method, array $params ) : mixed
$method string The name of native method to call. See the link above for available class methods.
$params array A list of parameters to be passed to the native method.
리턴 mixed The return value of the native method specified in `$method`.

__construct() 공개 메소드

Constructor.
또한 보기: lithium\data\Connections::add()
또한 보기: lithium\data\source\MongoDb::$_schema
public __construct ( array $config = [] ) : void
$config array Configuration options required to connect to the database, including: - `'database'` _string_: The name of the database to connect to. Defaults to `null`. - `'host'` _string_: The IP or machine name where Mongo is running, followed by a colon, and the port number. Defaults to `'localhost:27017'`. - `'persistent'` _mixed_: Determines a persistent connection to attach to. See the `$options` parameter of [`Mongo::__construct()`](http://php.net/mongo.construct.php) for more information. Defaults to `false`, meaning no persistent connection is made. - `'timeout'` _integer_: The number of milliseconds a connection attempt will wait before timing out and throwing an exception. Defaults to `100`. - `'schema'` _\Closure_: A closure or anonymous function which returns the schema information for a model class. See the `$_schema` property for more information. - `'gridPrefix'` _string_: The default prefix for MongoDB's `chunks` and `files` collections. Defaults to `'fs'`. - `'replicaSet'` _string_: See the documentation for `Mongo::__construct()`. Defaults to `false`. - `'readPreference'` _mixed_: May either be a single value such as Mongo::RP_NEAREST, or an array containing a read preference and a tag set such as: array(Mongo::RP_SECONDARY_PREFERRED, array('dc' => 'east) See the documentation for `Mongo::setReadPreference()`. Defaults to null. Typically, these parameters are set in `Connections::add()`, when adding the adapter to the list of active connections.
리턴 void

__destruct() 공개 메소드

Destructor. Ensures that the server connection is closed and resources are freed when the adapter instance is destroyed.
public __destruct ( ) : void
리턴 void

_checkConnection() 보호된 메소드

protected _checkConnection ( )

_conditions() 보호된 메소드

Protected helper method used to format conditions.
protected _conditions ( array $conditions, string $model, object $schema, object $context ) : array
$conditions array The conditions array to be processed.
$model string The name of the model class used in the query.
$schema object The object containing the schema definition.
$context object The `Query` object.
리턴 array Processed query conditions.

_deleteFile() 보호된 메소드

protected _deleteFile ( $conditions, $options = [] )

_group() 보호된 메소드

protected _group ( $group, $args, $options )

_init() 보호된 메소드

Initializer. Adds operator handlers which will later allow to correctly cast any values.
또한 보기: lithium\data\source\MongoDb::$_operators
또한 보기: lithium\data\source\MongoDb::_operators()
protected _init ( ) : void
리턴 void

_isMongoCode() 보호된 메소드

protected _isMongoCode ( $conditions )

_ok() 보호된 메소드

Parse a MongoCollection::() response and return true on success.
protected _ok ( $result ) : boolean
리턴 boolean

_operators() 보호된 메소드

protected _operators ( $field, $operators, $schema )

_saveFile() 보호된 메소드

protected _saveFile ( $data )

calculation() 공개 메소드

Executes calculation-related queries, such as those required for count.
public calculation ( string $type, mixed $query, array $options = [] ) : integer
$type string Only accepts `count`.
$query mixed The query to be executed.
$options array Optional arguments for the `read()` query that will be executed to obtain the calculation result.
리턴 integer Result of the calculation.

conditions() 공개 메소드

Maps incoming conditions with their corresponding MongoDB-native operators.
public conditions ( array $conditions, object $context ) : array
$conditions array Array of conditions
$context object Context with which this method was called; currently inspects the return value of `$context->type()`.
리턴 array Transformed conditions

configureClass() 공개 메소드

Configures a model class by overriding the default dependencies for 'set' and 'entity' , and sets the primary key to '_id', in keeping with Mongo's conventions.
또한 보기: lithium\data\Model::$_meta
또한 보기: lithium\data\Model::$_classes
public configureClass ( string $class ) : Returns
$class string The fully-namespaced model class name to be configured.
리턴 Returns an array containing keys `'classes'` and `'meta'`, which will be merged with their respective properties in `Model`.

connect() 공개 메소드

Connects to the Mongo server. Matches up parameters from the constructor to create a Mongo database connection.
또한 보기: lithium\data\source\MongoDb::__construct()
public connect ( ) : boolean
리턴 boolean Returns `true` the connection attempt was successful, otherwise `false`.

create() 공개 메소드

Create new document
public create ( string $query, array $options = [] ) : boolean
$query string
$options array
리턴 boolean

delete() 공개 메소드

Delete document
public delete ( string $query, array $options = [] ) : boolean
$query string
$options array
리턴 boolean

describe() 공개 메소드

Gets the column 'schema' for a given MongoDB collection. Only returns a schema if the 'schema' configuration flag has been set in the constructor.
또한 보기: lithium\data\source\MongoDb::$_schema
public describe ( mixed $collection, mixed $fields = [], array $meta = [] ) : array
$collection mixed Specifies a collection name for which the schema should be queried.
$fields mixed Any schema data pre-defined by the model.
$meta array Any meta information pre-defined in the model.
리턴 array Returns an associative array describing the given collection's schema.

disconnect() 공개 메소드

Don't call the Mongo->close() method. The driver documentation states this should not be necessary since it auto disconnects when out of scope. With version 1.2.7, when using replica sets, close() can cause a segmentation fault.
public disconnect ( ) : boolean
리턴 boolean True

enabled() 공개 정적인 메소드

With no parameter, checks to see if the mongo extension is installed. With a parameter, queries for a specific supported feature.
public static enabled ( string $feature = null ) : boolean
$feature string Test for support for a specific feature, i.e. `"transactions"` or `"arrays"`.
리턴 boolean Returns `true` if the particular feature (or if MongoDB) support is enabled, otherwise `false`.

fields() 공개 메소드

MongoDB does nt require field identifer escaping; as a result, this method is not implemented.
public fields ( array $fields, object $context ) : array
$fields array Fields to be parsed
$context object
리턴 array Parsed fields array

group() 공개 메소드

Formats group clauses for MongoDB.
public group ( string | array $group, object $context ) : array
$group string | array The group clause.
$context object
리턴 array Formatted `group` clause.

limit() 공개 메소드

MongoDB doesn't require limit identifer formatting; as a result, this method is not implemented.
public limit ( mixed $limit, object $context ) : mixed
$limit mixed The `limit` clause to be formatted.
$context object The `Query` object instance.
리턴 mixed Formatted `limit` clause.

name() 공개 메소드

MongoDb does not need identifiers quoted, so this method simply returns the identifier.
public name ( string $name ) : string
$name string The identifier to quote.
리턴 string The quoted identifier.

order() 공개 메소드

Return formatted clause for order.
public order ( mixed $order, object $context ) : mixed
$order mixed The `order` clause to be formatted
$context object
리턴 mixed Formatted `order` clause.

read() 공개 메소드

Read from document
public read ( string $query, array $options = [] ) : object
$query string
$options array
리턴 object

relationFieldName() 공개 메소드

Returns the field name of a relation name (camelBack).
public relationFieldName ( $type, $name ) : string
리턴 string

relationship() 공개 메소드

Document relationships.
public relationship ( string $class, string $type, string $name, array $config = [] ) : array
$class string
$type string Relationship type, e.g. `belongsTo`.
$name string
$config array
리턴 array

respondsTo() 공개 메소드

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
리턴 boolean Returns `true` if the method can be called, `false` otherwise.

schema() 공개 메소드

Normally used in cases where the query is a raw string (as opposed to a Query object), to database must determine the correct column names from the result resource. Not applicable to this data source.
public schema ( $query, $resource = null, $context = null ) : array
리턴 array

sources() 공개 메소드

Returns the list of collections in the currently-connected database.
public sources ( string $class = null ) : array
$class string The fully-name-spaced class name of the model object making the request.
리턴 array Returns an array of objects to which models can connect.

update() 공개 메소드

Update document
public update ( string $query, array $options = [] ) : boolean
$query string
$options array
리턴 boolean

프로퍼티 상세

$_autoConfig 보호되어 있는 프로퍼티

List of configuration keys which will be automatically assigned to their corresponding protected class properties.
protected array $_autoConfig
리턴 array

$_boolean 보호되어 있는 프로퍼티

List of comparison operators to use when performing boolean logic in a query.
protected array $_boolean
리턴 array

$_classes 보호되어 있는 프로퍼티

Classes used by this class.
protected array $_classes
리턴 array

$_operators 보호되어 있는 프로퍼티

Map of typical SQL-like operators to their MongoDB equivalents.
protected $_operators

$_schema 보호되어 있는 프로퍼티

A closure or anonymous function which receives an instance of this class, a collection name and associated meta information, and returns an array defining the schema for an associated model, where the keys are field names, and the values are arrays defining the type information for each field. At a minimum, type arrays must contain a 'type' key. For more information on schema definitions, and an example schema callback implementation, see the $_schema property of the Model class.
또한 보기: lithium\data\Model::$_schema
protected Closure $_schema
리턴 Closure

$connection 공개적으로 프로퍼티

The MongoDB object instance.
public object $connection
리턴 object

$server 공개적으로 프로퍼티

The Mongo class instance.
public object $server
리턴 object