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. (https://cakefoundation.org)
License: MIT License
Location: Cake/Model/ConnectionManager.php
Properties summary
- Contains a list of all file and class names used in Connection settings
array
- Holds instances DataSource objects
array
- Indicates if the init code for this class has already been executed
boolean
- Holds a loaded instance of the Connections object
DATABASE_CONFIG
Method Summary
- Returns the file, class name, and parent for the given driver.
- Gets a list of class and file names associated with the user-defined DataSource connections
- Loads connections configuration.
- Dynamically creates a DataSource object at runtime, with the given name and settings
- Removes a connection configuration at runtime given its name
- Returns a list of connections
- Gets a reference to a DataSource object
- Gets a DataSource name from an object reference.
- Loads the DataSource class for the given connection name
-
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()source 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
arrayAn indexed array with: filename, classname, plugin and parent
_getConnectionObject()source 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
MissingDatasourceConfigException
create()source 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
DataSource
|nullA reference to the DataSource object, or null if creation failed
drop()source 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
booleansuccess if connection was removed, false if it does not exist
enumConnectionObjects()source public static
enumConnectionObjects( )
Returns a list of connections
Returns
arrayAn 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()source 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
DataSource
Instance
Throws
MissingDatasourceException
getSourceName()source public static
getSourceName( DataSource $source )
Gets a DataSource name from an object reference.
Parameters
-
DataSource
$source
- DataSource object
Returns
string|nullDatasource name, or null if source is not present in the ConnectionManager.
loadDataSource()source 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
booleanTrue on success, null on failure or false if the class is already loaded
Throws
MissingDatasourceException
sourceList()source 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
arrayList of available connections
Properties detail
$_connectionsEnumsource
protected static array
Contains a list of all file and class names used in Connection settings
array()
$_initsource
protected static boolean
Indicates if the init code for this class has already been executed
false
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.10/class-ConnectionManager.html