PHP Класс lithium\data\Source

In addition to utility methods and standardized properties, it defines the implementation tasks for all Lithium classes that work with external data, such as connections to remote resources (connect() and disconnect()), introspecting available data objects (entities() and describe()), and a standard read/write interface (create(), read(), update() and delete()). Subclasses may implement any other non-standard functionality, but the above methods define the requirements for interacting with Model objects, and other classes within lithium\data.
Наследование: extends lithium\core\Object
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$connection mixed Stores a connection to a remote resource. Usually a database connection (resource type), or an HTTP connection object ('object' type).

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

Свойство Тип Описание
$_autoConfig array The list of object properties to be automatically assigned from configuration passed to __construct().
$_cachedMethods array Holds cached methods.
$_classes array Default entity and set classes used by subclasses of Source.
$_isConnected boolean Stores the status of this object's connection. Updated when connect() or disconnect() are called, or if an error occurs that closes the object's connection.

Открытые методы

Метод Описание
__construct ( array $config = [] ) : void Constructor.
__destruct ( ) : void Destructor. Ensures the connection is closed, before the object is destroyed.
applyStrategy ( array $options, object $context ) Applying a strategy to a lithium\data\model\Query object
configureClass ( string $class ) : array A method which can be optionally implemented to configure a model class.
connect ( ) Abstract. Must be defined by child classes.
create ( mixed $query, array $options = [] ) : boolean Create a record. This is the abstract method that is implemented by specific data sources.
delete ( mixed $query, array $options = [] ) : boolean Abstract. Must be defined by child classes.
describe ( mixed $entity, array $schema = [], array $meta = [] ) : array Gets the column schema for a given entity (such as a database table).
disconnect ( ) Abstract. Must be defined by child classes.
enabled ( string $feature = null ) : boolean With no parameter, checks a specific supported feature.
isConnected ( array $options = [] ) : boolean Checks the connection status of this data source. If the 'autoConnect' option is set to true and the source connection is not currently active, a connection attempt will be made before returning the result of the connection status.
methods ( ) : array Returns the list of methods which format values imported from Query objects. Should be overridden in subclasses.
name ( string $name ) : string Quotes data-source-native identifiers, where applicable.
read ( mixed $query, array $options = [] ) : boolean Abstract. Must be defined by child classes.
relationFieldName ( $type, $name ) : string Returns the field name of a relation name (underscore).
relationship ( $class, $type, $name, array $options = [] ) : array Defines or modifies the default settings of a relationship between two models.
sources ( string $class = null ) : array Returns a list of objects (sources) that models can bind to, i.e. a list of tables in the case of a database, or REST collections, in the case of a web service.
update ( mixed $query, array $options = [] ) : boolean Updates a set of records in a concrete data store.

Защищенные методы

Метод Описание
_init ( )

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( array $config = [] ) : void
$config array Available options are: - `'autoConnect'` _boolean_: If `true`, a connection is made on initialization. Defaults to `true`.
Результат void

__destruct() публичный Метод

Destructor. Ensures the connection is closed, before the object is destroyed.
public __destruct ( ) : void
Результат void

_init() защищенный Метод

protected _init ( )

applyStrategy() публичный Метод

Applying a strategy to a lithium\data\model\Query object
public applyStrategy ( array $options, object $context )
$options array The option array
$context object A query object to configure

configureClass() публичный Метод

A method which can be optionally implemented to configure a model class.
См. также: lithium\data\Model::$_meta
См. также: lithium\data\Model::$_finders
См. также: lithium\data\Model::$_classes
public configureClass ( string $class ) : array
$class string The name of the model class to be configured.
Результат array This method should return an array one or more of the following keys: `'meta'`, `'classes'` or `'finders'`. These keys maps to the three corresponding properties in `lithium\data\Model`, and are used to override the base-level default settings and dependencies.

connect() абстрактный публичный Метод

Abstract. Must be defined by child classes.
abstract public connect ( )

create() абстрактный публичный Метод

This method should take a query object and use it to create a record in the data source.
abstract public create ( mixed $query, array $options = [] ) : boolean
$query mixed An object which defines the update operation(s) that should be performed against the data store. This can be a `Query`, a `RecordSet`, a `Record`, or a subclass of one of the three. Alternatively, `$query` can be an adapter-specific query string.
$options array The options from Model include, - `validate` _boolean_ default: true - `events` _string_ default: create - `whitelist` _array_ default: null - `callbacks` _boolean_ default: true - `locked` _boolean_ default: true
Результат boolean Returns true if the operation was a success, otherwise false.

delete() абстрактный публичный Метод

Abstract. Must be defined by child classes.
abstract public delete ( mixed $query, array $options = [] ) : boolean
$query mixed
$options array
Результат boolean Returns true if the operation was a success, otherwise false.

describe() абстрактный публичный Метод

Gets the column schema for a given entity (such as a database table).
abstract public describe ( mixed $entity, array $schema = [], array $meta = [] ) : array
$entity mixed Specifies the table name for which the schema should be returned, or the class name of the model object requesting the schema, in which case the model class will be queried for the correct table name.
$schema array
$meta array The meta-information for the model class, which this method may use in introspecting the schema.
Результат array Returns a `Schema` object describing the given model's schema, where the array keys are the available fields, and the values are arrays describing each field, containing the following keys: - `'type'`: The field type name

disconnect() абстрактный публичный Метод

Abstract. Must be defined by child classes.
abstract public disconnect ( )

enabled() публичный статический Метод

With no parameter, checks 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`.

isConnected() публичный Метод

Checks the connection status of this data source. If the 'autoConnect' option is set to true and the source connection is not currently active, a connection attempt will be made before returning the result of the connection status.
public isConnected ( array $options = [] ) : boolean
$options array The options available for this method: - 'autoConnect': If true, and the connection is not currently active, calls `connect()` on this object. Defaults to `false`.
Результат boolean Returns the current value of `$_isConnected`, indicating whether or not the object's connection is currently active. This value may not always be accurate, as the connection could have timed out or otherwise been dropped by the remote resource during the course of the request.

methods() публичный Метод

Returns the list of methods which format values imported from Query objects. Should be overridden in subclasses.
См. также: lithium\data\model\Query
public methods ( ) : array
Результат array

name() публичный Метод

Quotes data-source-native identifiers, where applicable.
public name ( string $name ) : string
$name string Identifier name.
Результат string Returns `$name`, quoted if applicable.

read() абстрактный публичный Метод

Abstract. Must be defined by child classes.
abstract public read ( mixed $query, array $options = [] ) : boolean
$query mixed
$options array
Результат boolean Returns true if the operation was a success, otherwise false.

relationFieldName() публичный Метод

Returns the field name of a relation name (underscore).
public relationFieldName ( $type, $name ) : string
Результат string

relationship() абстрактный публичный Метод

Defines or modifies the default settings of a relationship between two models.
abstract public relationship ( $class, $type, $name, array $options = [] ) : array
$class the primary model of the relationship
$type the type of the relationship (hasMany, hasOne, belongsTo)
$name the name of the relationship
$options array relationship options
Результат array Returns an array containing the configuration for a model relationship.

sources() абстрактный публичный Метод

Returns a list of objects (sources) that models can bind to, i.e. a list of tables in the case of a database, or REST collections, in the case of a web service.
abstract public sources ( string $class = null ) : array
$class string The fully-name-spaced class name of the object making the request.
Результат array Returns an array of objects to which models can connect.

update() абстрактный публичный Метод

Updates a set of records in a concrete data store.
abstract public update ( mixed $query, array $options = [] ) : boolean
$query mixed An object which defines the update operation(s) that should be performed against the data store. This can be a `Query`, a `RecordSet`, a `Record`, or a subclass of one of the three. Alternatively, `$query` can be an adapter-specific query string.
$options array Options to execute, which are defined by the concrete implementation.
Результат boolean Returns true if the update operation was a success, otherwise false.

Описание свойств

$_autoConfig защищенное свойство

The list of object properties to be automatically assigned from configuration passed to __construct().
protected array $_autoConfig
Результат array

$_cachedMethods защищенное свойство

Holds cached methods.
См. также: lithium\data\Source::methods()
protected array $_cachedMethods
Результат array

$_classes защищенное свойство

Default entity and set classes used by subclasses of Source.
protected array $_classes
Результат array

$_isConnected защищенное свойство

Stores the status of this object's connection. Updated when connect() or disconnect() are called, or if an error occurs that closes the object's connection.
protected bool $_isConnected
Результат boolean

$connection публичное свойство

Stores a connection to a remote resource. Usually a database connection (resource type), or an HTTP connection object ('object' type).
public mixed $connection
Результат mixed