1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

DibiResult is configured via items 'detectTypes' and 'formatDateTime' in 'result' subarray; removed RESULT_DETECT_TYPES & RESULT_DATE_TIME

This commit is contained in:
David Grudl
2010-05-19 20:25:17 +02:00
parent 9d803869fa
commit 88b1a45e42
3 changed files with 15 additions and 11 deletions

View File

@@ -167,13 +167,7 @@ class dibi
const REVISION = '$WCREV$ released on $WCDATE$';
/**#@-*/
/**#@+
* Configuration options
*/
const RESULT_DETECT_TYPES = 'resultDetectTypes';
const RESULT_DATE_TIME = 'resultDateTime';
const ASC = 'ASC', DESC = 'DESC';
/**#@-*/
/** @var DibiConnection[] Connection registry storage for DibiConnection objects */
private static $registry = array();

View File

@@ -55,7 +55,11 @@ class DibiConnection extends DibiObject
parse_str($config, $config);
} elseif ($config instanceof Traversable) {
$config = iterator_to_array($config);
$tmp = array();
foreach ($config as $key => $val) {
$tmp[$key] = $val instanceof Traversable ? iterator_to_array($val) : $val;
}
$config = $tmp;
} elseif (!is_array($config)) {
throw new InvalidArgumentException('Configuration must be array, string or object.');
@@ -64,6 +68,8 @@ class DibiConnection extends DibiObject
self::alias($config, 'username', 'user');
self::alias($config, 'password', 'pass');
self::alias($config, 'host', 'hostname');
self::alias($config, 'result|detectTypes', 'resultDetectTypes'); // back compatibility
self::alias($config, 'result|formatDateTime', 'resultDateTime');
if (!isset($config['driver'])) {
$config['driver'] = dibi::$defaultDriver;
@@ -324,7 +330,7 @@ class DibiConnection extends DibiObject
dibi::$sql = $sql;
if ($res = $this->driver->query($sql)) { // intentionally =
$res = new DibiResult($res, $this->config);
$res = new DibiResult($res, $this->config['result']);
} else {
$res = $this->driver->getAffectedRows();
}

View File

@@ -28,6 +28,10 @@
* unset($result);
* </code>
*
* Result options:
* - 'detectTypes' - whether call automatically detectTypes()
* - 'formatDateTime' - how to format datetime
*
* @copyright Copyright (c) 2005, 2010 David Grudl
* @package dibi
*
@@ -68,12 +72,12 @@ class DibiResult extends DibiObject implements IDataSource
{
$this->driver = $driver;
if (!empty($config[dibi::RESULT_DETECT_TYPES])) {
if (!empty($config['detectTypes'])) {
$this->detectTypes();
}
if (!empty($config[dibi::RESULT_DATE_TIME])) {
$this->dateFormat = is_string($config[dibi::RESULT_DATE_TIME]) ? $config[dibi::RESULT_DATE_TIME] : '';
if (!empty($config['formatDateTime'])) {
$this->dateFormat = is_string($config['formatDateTime']) ? $config['formatDateTime'] : '';
}
}