1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-03 20:57:36 +02:00

Connection, Results: refactorings, added Result::setFormats()

This commit is contained in:
David Grudl
2020-10-08 17:12:21 +02:00
parent decb30de1e
commit a9e90d0b22
2 changed files with 22 additions and 6 deletions

View File

@@ -28,6 +28,9 @@ class Connection implements IConnection
/** @var array Current connection configuration */
private $config;
/** @var string[] resultset formats */
private $formats;
/** @var Driver|null */
private $driver;
@@ -65,9 +68,14 @@ class Connection implements IConnection
Helpers::alias($config, 'result|formatDateTime', 'resultDateTime');
$config['driver'] = $config['driver'] ?? 'mysqli';
$config['name'] = $name;
$config['result']['formatJson'] = $config['result']['formatJson'] ?? 'array';
$this->config = $config;
$this->formats = [
Type::DATE => $this->config['result']['formatDate'],
Type::DATETIME => $this->config['result']['formatDateTime'],
Type::JSON => $this->config['result']['formatJson'] ?? 'array',
];
// profiler
if (isset($config['profiler']['file']) && (!isset($config['profiler']['run']) || $config['profiler']['run'])) {
$filter = $config['profiler']['filter'] ?? Event::QUERY;
@@ -391,10 +399,8 @@ class Connection implements IConnection
*/
public function createResultSet(ResultDriver $resultDriver): Result
{
$res = new Result($resultDriver);
return $res->setFormat(Type::DATE, $this->config['result']['formatDate'])
->setFormat(Type::DATETIME, $this->config['result']['formatDateTime'])
->setFormat(Type::JSON, $this->config['result']['formatJson']);
return (new Result($resultDriver))
->setFormats($this->formats);
}

View File

@@ -549,7 +549,7 @@ class Result implements IDataSource
/**
* Sets date format.
* Sets type format.
*/
final public function setFormat(string $type, ?string $format): self
{
@@ -558,6 +558,16 @@ class Result implements IDataSource
}
/**
* Sets type formats.
*/
final public function setFormats(array $formats): self
{
$this->formats = $formats;
return $this;
}
/**
* Returns data format.
*/