Manages and loads instances of Connection
Provides an interface to loading and creating connection objects. Acts as a registry for the connections defined in an application.
Provides an interface for loading and enumerating connections defined in config/app.php
alias( string $from , string $to )
Set one or more connection aliases.
Connection aliases allow you to rename active connections without overwriting the aliased connection. This is most useful in the test-suite for replacing connections with their test variant.
Defined aliases will take precedence over normal connection names. For example, if you alias 'default' to 'test', fetching 'default' will always return the 'test' connection as long as the alias is defined.
You can remove aliases with ConnectionManager::dropAlias().
$from $to Cake\Datasource\Exception\MissingDatasourceConfigExceptionconfig( string|array $key , array $config null )
Configure a new connection object.
The connection will not be constructed until it is first used.
$key $config optional null array|nullCake\Core\Exception\ExceptionCake\Core\StaticConfigTrait::config()dropAlias( string $name )
Drop an alias.
Removes an alias from ConnectionManager. Fetching the aliased connection may fail if there is no other connection with that name.
$name get( string $name , boolean $useAliases true )
Get a connection.
If the connection has not been constructed an instance will be added to the registry. This method will use any aliases that have been defined. If you want the original unaliased connections pass false as second parameter.
$name $useAliases optional true Cake\Datasource\ConnectionInterfaceCake\Datasource\Exception\MissingDatasourceConfigExceptionparseDsn( string|null $config null )
Parses a DSN into a valid connection configuration
This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:
$dsn = 'mysql://user:pass@localhost/database'; $config = ConnectionManager::parseDsn($dsn); $dsn = 'Cake\Database\Driver\Mysql://localhost:3306/database?className=Cake\Database\Connection'; $config = ConnectionManager::parseDsn($dsn); $dsn = 'Cake\Database\Connection://localhost:3306/database?driver=Cake\Database\Driver\Mysql'; $config = ConnectionManager::parseDsn($dsn);
For all classes, the value of scheme is set as the value of both the className and driver unless they have been otherwise specified.
Note that query-string arguments are also parsed and set as values in the returned configuration.
$config optional null array_config( string|array $key , array $config null )
This method can be used to define configuration adapters for an application or read existing configuration.
To change an adapter's configuration at runtime, first drop the adapter and then reconfigure it.
Adapters will not be constructed until the first operation is done.
Assuming that the class' name is Cache the following scenarios are supported:
Reading config data back:
Cache::config('default');
Setting a cache engine up.
Cache::config('default', $settings);
Injecting a constructed adapter in:
Cache::config('default', $instance);
Configure multiple adapters at once:
Cache::config($arrayOfConfig);
$key $config optional null array|nullBadMethodCallException_parseDsn( string $dsn )
Parses a DSN into a valid connection configuration
This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:
$dsn = 'mysql://user:pass@localhost/database?'; $config = ConnectionManager::parseDsn($dsn); $dsn = 'Cake\Log\Engine\FileLog://?types=notice,info,debug&file=debug&path=LOGS'; $config = Log::parseDsn($dsn); $dsn = 'smtp://user:secret@localhost:25?timeout=30&client=null&tls=null'; $config = Email::parseDsn($dsn); $dsn = 'file:///?className=\My\Cache\Engine\FileEngine'; $config = Cache::parseDsn($dsn); $dsn = 'File://?prefix=myapp_cake_core_&serialize=true&duration=+2 minutes&path=/tmp/persistent/'; $config = Cache::parseDsn($dsn);
For all classes, the value of scheme is set as the value of both the className unless they have been otherwise specified.
Note that querystring arguments are also parsed and set as values in the returned configuration.
$dsn arrayInvalidArgumentExceptionconfigured( )
Returns an array containing the named configurations
arraydrop( string $config )
Drops a constructed adapter.
If you wish to modify an existing configuration, you should drop it, change configuration and then re-add it.
If the implementing objects supports a $_registry object the named configuration will also be unloaded from the registry.
$config booleandsnClassMap( array $map null )
Returns or updates the DSN class map for this class
$map optional null array
© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Datasource.ConnectionManager.html