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

Connection: translator is created/destructed in connect/disconnect [Closes #352][Closes #354]

This commit is contained in:
David Grudl
2020-02-14 12:39:17 +01:00
parent 4d647c2aed
commit 2cbebc02c4

View File

@@ -119,6 +119,7 @@ class Connection implements IConnection
{ {
if ($this->config['driver'] instanceof Driver) { if ($this->config['driver'] instanceof Driver) {
$this->driver = $this->config['driver']; $this->driver = $this->config['driver'];
$this->translator = new Translator($this);
return; return;
} elseif (is_subclass_of($this->config['driver'], Driver::class)) { } elseif (is_subclass_of($this->config['driver'], Driver::class)) {
@@ -135,6 +136,8 @@ class Connection implements IConnection
$event = $this->onEvent ? new Event($this, Event::CONNECT) : null; $event = $this->onEvent ? new Event($this, Event::CONNECT) : null;
try { try {
$this->driver = new $class($this->config); $this->driver = new $class($this->config);
$this->translator = new Translator($this);
if ($event) { if ($event) {
$this->onEvent($event->done()); $this->onEvent($event->done());
} }
@@ -160,7 +163,7 @@ class Connection implements IConnection
{ {
if ($this->driver) { if ($this->driver) {
$this->driver->disconnect(); $this->driver->disconnect();
$this->driver = null; $this->driver = $this->translator = null;
} }
} }
@@ -261,11 +264,7 @@ class Connection implements IConnection
if (!$this->driver) { if (!$this->driver) {
$this->connect(); $this->connect();
} }
if (!$this->translator) { return (clone $this->translator)->translate($args);
$this->translator = new Translator($this);
}
$translator = clone $this->translator;
return $translator->translate($args);
} }