From 55bb55f955f8ee023893eab79bd3de8155f8ed5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 16 Aug 2023 00:57:33 +0800 Subject: [PATCH] qqq --- Connection.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Connection.php b/Connection.php index dcd2190..b044bc1 100644 --- a/Connection.php +++ b/Connection.php @@ -96,6 +96,7 @@ class Connection extends Component $eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0); $eventProvider->on(Rollback::class, [$this, 'rollback'], 0); $eventProvider->on(Commit::class, [$this, 'commit'], 0); + $eventProvider->on('afterRequest', [$this, 'clear']); } @@ -183,15 +184,7 @@ class Connection extends Component { $this->storey--; if ($this->storey == 0) { - $pdo = Context::get($this->cds); - if ($pdo === null) { - return; - } - if ($pdo->inTransaction()) { - $pdo->rollback(); - } - $this->pool()->push($this->cds, $pdo); - Context::remove($this->cds); + $this->clear(); } } @@ -216,6 +209,25 @@ class Connection extends Component } + /** + * @return void + * @throws Exception + */ + public function clear(): void + { + /** @var PDO $pdo */ + $pdo = Context::get($this->cds); + if ($pdo === null) { + return; + } + if ($pdo->inTransaction()) { + $pdo->rollback(); + } + $this->pool()->push($this->cds, $pdo); + Context::remove($this->cds); + } + + /** * @param null $sql * @param array $attributes