From 9f71f394705cb8d29b390fc3cf2edf158fe6a5a3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 14 Feb 2020 12:39:17 +0100 Subject: [PATCH] Connection: translator is created/destructed in connect/disconnect [Closes #352][Closes #354] --- src/Dibi/Connection.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index 9938fa5b..141c6f0d 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -51,7 +51,7 @@ class Connection implements IConnection * - profiler (array) * - run (bool) => enable profiler? * - file => file to log - * - errorsOnly (bool) => log only errors + * - errorsOnly (bool) => log only errors * - substitutes (array) => map of driver specific substitutes (under development) * - onConnect (array) => list of SQL queries to execute (by Connection::query()) after connection is established * @throws Exception @@ -110,6 +110,7 @@ class Connection implements IConnection { if ($this->config['driver'] instanceof Driver) { $this->driver = $this->config['driver']; + $this->translator = new Translator($this); return; } elseif (is_subclass_of($this->config['driver'], Driver::class)) { @@ -126,6 +127,8 @@ class Connection implements IConnection $event = $this->onEvent ? new Event($this, Event::CONNECT) : null; try { $this->driver = new $class($this->config); + $this->translator = new Translator($this); + if ($event) { $this->onEvent($event->done()); } @@ -151,7 +154,7 @@ class Connection implements IConnection { if ($this->driver) { $this->driver->disconnect(); - $this->driver = null; + $this->driver = $this->translator = null; } } @@ -252,11 +255,7 @@ class Connection implements IConnection if (!$this->driver) { $this->connect(); } - if (!$this->translator) { - $this->translator = new Translator($this); - } - $translator = clone $this->translator; - return $translator->translate($args); + return (clone $this->translator)->translate($args); }