mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 12:47:33 +02:00
Connection, Results: refactorings, added Result::setFormats()
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user