From fff6858de895d47937a1d32d9019ecdae9779f91 Mon Sep 17 00:00:00 2001 From: Uyan712 Date: Tue, 23 Jan 2024 12:25:58 +0900 Subject: [PATCH] ensure existence of `setConnection` method --- src/Connection.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 1a22816..20d211f 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -23,6 +23,7 @@ use Colopl\TiDB\Schema\Grammar as SchemaGrammar; use Illuminate\Database\Grammar; use Illuminate\Database\MySqlConnection; +use function method_exists; class Connection extends MySqlConnection { @@ -31,7 +32,10 @@ class Connection extends MySqlConnection */ protected function getDefaultQueryGrammar() { - ($grammar = new QueryGrammar)->setConnection($this); + $grammar = new QueryGrammar; + if (method_exists($grammar, 'setConnection')) { + $grammar->setConnection($this); + } return $this->withTablePrefix($grammar); } @@ -41,7 +45,10 @@ protected function getDefaultQueryGrammar() */ protected function getDefaultSchemaGrammar() { - ($grammar = new SchemaGrammar)->setConnection($this); + $grammar = new SchemaGrammar; + if (method_exists($grammar, 'setConnection')) { + $grammar->setConnection($this); + } return $this->withTablePrefix($grammar); }