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
파일 보기 프로젝트 열기: unionofrad/lithium 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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`