Skip to content

Commit

Permalink
Add DSN parsing support to the Log class
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez committed Oct 12, 2014
1 parent 9d78414 commit 53a0868
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Log/Log.php
Expand Up @@ -105,6 +105,7 @@ class Log {

use StaticConfigTrait {
config as protected _config;
parseDsn as protected _parseDsn;
}

/**
Expand Down Expand Up @@ -258,6 +259,40 @@ public static function config($key, $config = null) {
static::$_dirtyConfig = true;
}

/**
* Parses a dsn into a valid connection configuration
*
* This method allows setting a dsn using PEAR::DB formatting, with added support for drivers
* in the SQLAlchemy format. The following is an example of it's usage:
*
* {{{
* $dsn = 'Cake\Log\Engine\FileLog://?types=notice,info,debug&file=debug&path=LOGS';
* $config = Log::parseDsn($dsn);
* }}
*
* If an array is given, the parsed dsn will be merged into this array. Note that querystring
* arguments are also parsed and set as values in the returned configuration.
*
* There is a special replacement value for the string `LOGS`, which is replaced by the LOGS constant.
*
* @param array $config An array with a `url` key mapping to a string dsn
* @return mixed null when adding configuration and an array of configuration data when reading.
*/
public static function parseDsn($config = null) {
if (is_array($config) && isset($config['url'])) {
$config['url'] = str_replace('LOGS', LOGS, $config['url']);
}

$config = static::_parseDsn($config);

if (isset($config['driver'])) {
$config['className'] = $config['driver'];
}

unset($config['driver']);
return $config;
}

/**
* Get a logging engine.
*
Expand Down

0 comments on commit 53a0868

Please sign in to comment.