Class ConnectionManager
Manages loaded instances of DataSource objects
Provides an interface for loading and enumerating connections defined in app/Config/database.php
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Model/ConnectionManager.php
Properties summary
-
$_connectionsEnum
protected staticarray
Contains a list of all file and class names used in Connection settings -
$_dataSources
protected staticarray
Holds instances DataSource objects -
$_init
protected staticboolean
Indicates if the init code for this class has already been executed -
$config
public staticDATABASE_CONFIG
Holds a loaded instance of the Connections object
Method Summary
-
_connectionData() protected static
Returns the file, class name, and parent for the given driver. -
_getConnectionObject() protected static
Gets a list of class and file names associated with the user-defined DataSource connections -
_init() protected static
Loads connections configuration. -
create() public static
Dynamically creates a DataSource object at runtime, with the given name and settings -
drop() public static
Removes a connection configuration at runtime given its name -
enumConnectionObjects() public static
Returns a list of connections -
getDataSource() public static
Gets a reference to a DataSource object -
getSourceName() public static
Gets a DataSource name from an object reference. -
loadDataSource() public static
Loads the DataSource class for the given connection name -
sourceList() public static
Gets the list of available DataSource connections This will only return the datasources instantiated by this manager It differs from enumConnectionObjects, since the latter will return all configured connections
Method Detail
_connectionData() protected static ¶
_connectionData( array $config )
Returns the file, class name, and parent for the given driver.
Parameters
- array $config
- Array with connection configuration. Key 'datasource' is required
Returns
An indexed array with: filename, classname, plugin and parent
_getConnectionObject() protected static ¶
_getConnectionObject( string $name )
Gets a list of class and file names associated with the user-defined DataSource connections
Parameters
- string $name
- Connection name
Throws
create() public static ¶
create( string $name = '' , array $config = array() )
Dynamically creates a DataSource object at runtime, with the given name and settings
Parameters
- string $name optional ''
- The DataSource name
- array $config optional array()
- The DataSource configuration settings
Returns
drop() public static ¶
drop( string $name )
Removes a connection configuration at runtime given its name
Parameters
- string $name
- the connection name as it was created
Returns
success if connection was removed, false if it does not exist
enumConnectionObjects() public static ¶
enumConnectionObjects( )
Returns a list of connections
Returns
An associative array of elements where the key is the connection name (as defined in Connections), and the value is an array with keys 'filename' and 'classname'.
getDataSource() public static ¶
getDataSource( string $name )
Gets a reference to a DataSource object
Parameters
- string $name
- The name of the DataSource, as defined in app/Config/database.php
Returns
Throws
getSourceName() public static ¶
getSourceName( DataSource
$source )
Gets a DataSource name from an object reference.
Parameters
-
DataSource
$source - DataSource object
Returns
Datasource name, or null if source is not present in the ConnectionManager.
loadDataSource() public static ¶
loadDataSource( string|array $connName )
Loads the DataSource class for the given connection name
Parameters
- string|array $connName
A string name of the connection, as defined in app/Config/database.php, or an array containing the filename (without extension) and class name of the object, to be found in app/Model/Datasource/ or lib/Cake/Model/Datasource/.
Returns
True on success, null on failure or false if the class is already loaded
Throws
sourceList() public static ¶
sourceList( )
Gets the list of available DataSource connections This will only return the datasources instantiated by this manager It differs from enumConnectionObjects, since the latter will return all configured connections
Returns
List of available connections
Properties detail
$_connectionsEnum ¶
Contains a list of all file and class names used in Connection settings
array()