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
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$connection object The MongoDB object instance.
$server object The Mongo class instance.

Защищенные свойства (Protected)

Свойство Тип Описание
$_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