PHP Class 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.
Inheritance: extends lithium\core\Object
Afficher le fichier Open project: unionofrad/lithium Class Usage Examples

Méthodes publiques

Свойство Type Description
$connection mixed Stores a connection to a remote resource. Usually a database connection (resource type), or an HTTP connection object ('object' type).

Protected Properties

Свойство Type Description
$_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.

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
_init ( )

Method Details

__construct() public méthode

Constructor.
public __construct ( array $config = [] ) : void
$config array Available options are: - `'autoConnect'` _boolean_: If `true`, a connection is made on initialization. Defaults to `true`.
Résultat void

__destruct() public méthode

Destructor. Ensures the connection is closed, before the object is destroyed.
public __destruct ( ) : void
Résultat void

_init() protected méthode

protected _init ( )

applyStrategy() public méthode

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() public méthode

A method which can be optionally implemented to configure a model class.
See also: lithium\data\Model::$_meta
See also: lithium\data\Model::$_finders
See also: lithium\data\Model::$_classes
public configureClass ( string $class ) : array
$class string The name of the model class to be configured.
Résultat 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 public méthode

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

create() abstract public méthode

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
Résultat boolean Returns true if the operation was a success, otherwise false.

delete() abstract public méthode

Abstract. Must be defined by child classes.
abstract public delete ( mixed $query, array $options = [] ) : boolean
$query mixed
$options array
Résultat boolean Returns true if the operation was a success, otherwise false.

describe() abstract public méthode

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.
Résultat 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 public méthode

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

enabled() public static méthode

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"`.
Résultat boolean Returns `true` if the particular feature (or if MongoDB) support is enabled, otherwise `false`.

isConnected() public méthode

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`.
Résultat 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() public méthode

Returns the list of methods which format values imported from Query objects. Should be overridden in subclasses.
See also: lithium\data\model\Query
public methods ( ) : array
Résultat array

name() public méthode

Quotes data-source-native identifiers, where applicable.
public name ( string $name ) : string
$name string Identifier name.
Résultat string Returns `$name`, quoted if applicable.

read() abstract public méthode

Abstract. Must be defined by child classes.
abstract public read ( mixed $query, array $options = [] ) : boolean
$query mixed
$options array
Résultat boolean Returns true if the operation was a success, otherwise false.

relationFieldName() public méthode

Returns the field name of a relation name (underscore).
public relationFieldName ( $type, $name ) : string
Résultat string

relationship() abstract public méthode

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
Résultat array Returns an array containing the configuration for a model relationship.

sources() abstract public méthode

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.
Résultat array Returns an array of objects to which models can connect.

update() abstract public méthode

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.
Résultat boolean Returns true if the update operation was a success, otherwise false.

Property Details

$_autoConfig protected_oe property

The list of object properties to be automatically assigned from configuration passed to __construct().
protected array $_autoConfig
Résultat array

$_cachedMethods protected_oe property

Holds cached methods.
See also: lithium\data\Source::methods()
protected array $_cachedMethods
Résultat array

$_classes protected_oe property

Default entity and set classes used by subclasses of Source.
protected array $_classes
Résultat array

$_isConnected protected_oe property

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
Résultat boolean

$connection public_oe property

Stores a connection to a remote resource. Usually a database connection (resource type), or an HTTP connection object ('object' type).
public mixed $connection
Résultat mixed