From 7eb80d607be56a30849fb4068bd91ff82cc975a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 3 Apr 2023 11:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Connection.php | 17 ++++++++--------- Db.php | 4 ++-- Relation.php | 18 +++++++++--------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Connection.php b/Connection.php index 33067b0..175690d 100644 --- a/Connection.php +++ b/Connection.php @@ -189,12 +189,12 @@ class Connection extends Component public function getPdo(bool $restore = false): Mysql\PDO { if ($restore === true) { - return Context::setContext($this->cds, $this->getMasterClient()); + return Context::set($this->cds, $this->getMasterClient()); } - if (!Context::hasContext($this->cds)) { - return Context::setContext($this->cds, $this->getMasterClient()); + if (!Context::exists($this->cds)) { + return Context::set($this->cds, $this->getMasterClient()); } else { - return Context::getContext($this->cds); + return Context::get($this->cds); } } @@ -254,11 +254,10 @@ class Connection extends Component */ public function release(Mysql\PDO $PDO) { -// if ($PDO->inTransaction()) { -// return; -// } - $this->connection->addItem($this->cds, $PDO); - Context::remove($this->cds); + if ($PDO->inTransaction() === false) { + $this->connection->addItem($this->cds, $PDO); + Context::remove($this->cds); + } } diff --git a/Db.php b/Db.php index 040611d..f25af03 100644 --- a/Db.php +++ b/Db.php @@ -37,7 +37,7 @@ class Db implements ISqlBuilder */ public static function inTransactionsActive(): bool { - return Context::hasContext('transactions::status') && Context::getContext('transactions::status') === true; + return Context::exists('transactions::status') && Context::get('transactions::status') === true; } @@ -46,7 +46,7 @@ class Db implements ISqlBuilder */ public static function beginTransaction(): void { - Context::setContext('transactions::status', true); + Context::set('transactions::status', true); } diff --git a/Relation.php b/Relation.php index 55644ce..1f1b360 100644 --- a/Relation.php +++ b/Relation.php @@ -55,14 +55,14 @@ class Relation extends Component */ public function first(string $_identification): mixed { - if (Context::hasContext($_identification)) { - return Context::getContext($_identification); + if (Context::exists($_identification)) { + return Context::get($_identification); } $activeModel = $this->_query[$_identification]->first(); if (empty($activeModel)) { return null; } - return Context::setContext($_identification, $activeModel); + return Context::set($_identification, $activeModel); } @@ -72,14 +72,14 @@ class Relation extends Component */ public function count(string $_identification): mixed { - if (Context::hasContext($_identification)) { - return Context::getContext($_identification); + if (Context::exists($_identification)) { + return Context::get($_identification); } $activeModel = $this->_query[$_identification]->count(); if (empty($activeModel)) { return null; } - return Context::setContext($_identification, $activeModel); + return Context::set($_identification, $activeModel); } @@ -89,14 +89,14 @@ class Relation extends Component */ public function get(string $_identification): mixed { - if (Context::hasContext($_identification)) { - return Context::getContext($_identification); + if (Context::exists($_identification)) { + return Context::get($_identification); } $activeModel = $this->_query[$_identification]->get(); if (empty($activeModel)) { return $activeModel; } - return Context::setContext($_identification, $activeModel); + return Context::set($_identification, $activeModel); } }