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 */
|
/** @var array Current connection configuration */
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
|
/** @var string[] resultset formats */
|
||||||
|
private $formats;
|
||||||
|
|
||||||
/** @var Driver|null */
|
/** @var Driver|null */
|
||||||
private $driver;
|
private $driver;
|
||||||
|
|
||||||
@@ -65,9 +68,14 @@ class Connection implements IConnection
|
|||||||
Helpers::alias($config, 'result|formatDateTime', 'resultDateTime');
|
Helpers::alias($config, 'result|formatDateTime', 'resultDateTime');
|
||||||
$config['driver'] = $config['driver'] ?? 'mysqli';
|
$config['driver'] = $config['driver'] ?? 'mysqli';
|
||||||
$config['name'] = $name;
|
$config['name'] = $name;
|
||||||
$config['result']['formatJson'] = $config['result']['formatJson'] ?? 'array';
|
|
||||||
$this->config = $config;
|
$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
|
// profiler
|
||||||
if (isset($config['profiler']['file']) && (!isset($config['profiler']['run']) || $config['profiler']['run'])) {
|
if (isset($config['profiler']['file']) && (!isset($config['profiler']['run']) || $config['profiler']['run'])) {
|
||||||
$filter = $config['profiler']['filter'] ?? Event::QUERY;
|
$filter = $config['profiler']['filter'] ?? Event::QUERY;
|
||||||
@@ -391,10 +399,8 @@ class Connection implements IConnection
|
|||||||
*/
|
*/
|
||||||
public function createResultSet(ResultDriver $resultDriver): Result
|
public function createResultSet(ResultDriver $resultDriver): Result
|
||||||
{
|
{
|
||||||
$res = new Result($resultDriver);
|
return (new Result($resultDriver))
|
||||||
return $res->setFormat(Type::DATE, $this->config['result']['formatDate'])
|
->setFormats($this->formats);
|
||||||
->setFormat(Type::DATETIME, $this->config['result']['formatDateTime'])
|
|
||||||
->setFormat(Type::JSON, $this->config['result']['formatJson']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -549,7 +549,7 @@ class Result implements IDataSource
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets date format.
|
* Sets type format.
|
||||||
*/
|
*/
|
||||||
final public function setFormat(string $type, ?string $format): self
|
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.
|
* Returns data format.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user