PHP Класс lithium\data\Connections

While connections can be added and removed dynamically during the course of your application (using Connections::add()), it is most typical to define all connections at once, in config/bootstrap/connections.php. The Connections class handles adapter classes efficiently by only loading adapter classes and creating instances when they are requested (using Connections::get()). Adapters are usually subclasses of lithium\data\Source.
См. также: lithium\data\Source
Наследование: extends lithium\core\Adaptable
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$_adapters Libraries::locate() compatible path to adapters for this class.
$_configurations `lithium\util\Collection` A Collection of the configurations you add through Connections::add().

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

Метод Описание
add ( string $name, array $config = [] ) : array Add connection configurations to your app in config/bootstrap/connections.php
get ( string $name = null, array $options = [] ) : mixed Read the configuration or access the connections you have set up.
remove ( string $name ) Removing a configuration.

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

Метод Описание
_class ( array $config, array $paths = [] ) : object Constructs a data source or adapter object instance from a configuration array.

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

_class() защищенный статический Метод

Constructs a data source or adapter object instance from a configuration array.
protected static _class ( array $config, array $paths = [] ) : object
$config array
$paths array
Результат object

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

For example: Connections::add('default', array( 'type' => 'database', 'adapter' => 'MySql', 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => 'my_blog' )); or Connections::add('couch', array( 'type' => 'http', 'adapter' => 'CouchDb', 'host' => '127.0.0.1', 'port' => 5984 )); or Connections::add('mongo', array('type' => 'MongoDb', 'database' => 'my_app'));
См. также: lithium\data\Model::$_meta
public static add ( string $name, array $config = [] ) : array
$name string The name by which this connection is referenced. Use this name to retrieve the connection again using `Connections::get()`, or to bind a model to it using `Model::$_meta['connection']`.
$config array Contains all additional configuration information used by the connection, including the name of the adapter class where applicable (i.e. `MySql`), the server name and port or socket to connect to, and (typically) the name of the database or other entity to use. Each adapter has its own specific configuration settings for handling things like connection persistence, data encoding, etc. See the individual adapter or data source class for more information on what configuration settings it supports. Basic / required options supported by most adapters: - `'type'` _string_: The type of data source that defines this connection; typically a class or namespace name. Relational database data sources, use `'database'`, while CouchDB and other HTTP-related data sources use `'http'`, etc. For classes which directly extend `lithium\data\Source`, and do not use an adapter, simply use the name of the class, i.e. `'MongoDb'`. - `'adapter'` _string_: For `type`s such as `'database'` which are adapter-driven, provides the name of the adapter associated with this configuration. - `'host'` _string_: The host name that the database should connect to. Typically defaults to `'localhost'`. - `'login'` _string_: If the connection requires authentication, specifies the login name to use. - `'password'` _string_: If the connection requires authentication, specifies the password to use.
Результат array Returns the final post-processed connection information, as stored in the internal configuration array used by `Connections`.

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

Usage: Gets the names of all available configurations $configurations = Connections::get(); Gets the configuration array for the connection named 'db' $config = Connections::get('db', array('config' => true)); Gets the instance of the connection object, configured with the settings defined for this object in Connections::add() $dbConnection = Connections::get('db'); Gets the connection object, but only if it has already been built. Otherwise returns null. $dbConnection = Connections::get('db', array('autoCreate' => false));
public static get ( string $name = null, array $options = [] ) : mixed
$name string The name of the connection to get, as defined in the first parameter of `add()`, when the connection was initially created.
$options array Options to use when returning the connection: - `'autoCreate'`: If `false`, the connection object is only returned if it has already been instantiated by a previous call. - `'config'`: If `true`, returns an array representing the connection's internal configuration, instead of the connection itself.
Результат mixed A configured instance of the connection, or an array of the configuration used.

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

Removing a configuration.
public static remove ( string $name )
$name string The name by which this connection is referenced.

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

$_adapters защищенное статическое свойство

Libraries::locate() compatible path to adapters for this class.
protected static $_adapters

$_configurations защищенное статическое свойство

A Collection of the configurations you add through Connections::add().
protected static `lithium\util\Collection` $_configurations
Результат `lithium\util\Collection`