Class ConnectionManager

Manages loaded instances of DataSource objects

Provides an interface for loading and enumerating connections defined in app/Config/database.php

Package: Cake\Model
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Model/ConnectionManager.php

Properties summary

  • $_connectionsEnum protected static
    array
    Contains a list of all file and class names used in Connection settings
  • $_dataSources protected static
    array
    Holds instances DataSource objects
  • $_init protected static
    boolean
    Indicates if the init code for this class has already been executed
  • $config public static
    DATABASE_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()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

array
An 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

_init()source protected static

_init( )

Loads connections configuration.

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|null
A 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

boolean
success if connection was removed, false if it does not exist

enumConnectionObjects()source public static

enumConnectionObjects( )

Returns a list of connections

Returns

array

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()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|null

Datasource 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

boolean
True 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

array
List of available connections

Properties detail

$_connectionsEnumsource

protected static array

Contains a list of all file and class names used in Connection settings

array()

$_dataSourcessource

protected static array

Holds instances DataSource objects

array()

$_initsource

protected static boolean

Indicates if the init code for this class has already been executed

false

$configsource

public static DATABASE_CONFIG

Holds a loaded instance of the Connections object

null

© 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