From 0ef3ce024da284775bc0812701ca670a743b24db Mon Sep 17 00:00:00 2001 From: Maxim Date: Mon, 10 Jun 2024 18:21:19 +0300 Subject: [PATCH] feat: Added doctrine/dbal v4.0. (#7) * #6 Added doctrine/dbal v4.0. * fix: Apply suggestions from code review --------- Co-authored-by: Jon --- composer.json | 2 +- src/Adapter.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 6d06910..f8eb2f1 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "license": "Apache-2.0", "require": { "casbin/casbin": "^3.0", - "doctrine/dbal": "^2.9|^3.0" + "doctrine/dbal": "^2.9|^3.0|^4.0" }, "require-dev": { "phpunit/phpunit": "~7.0|~8.0", diff --git a/src/Adapter.php b/src/Adapter.php index bb07a0e..447b81b 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -97,7 +97,7 @@ public static function newAdapter($connection): Adapter */ public function initTable() { - $sm = $this->connection->getSchemaManager(); + $sm = method_exists($this->connection, "createSchemaManager") ? $sm = $this->connection->createSchemaManager() : $sm = $this->connection->getSchemaManager(); if (!$sm->tablesExist([$this->policyTableName])) { $schema = new Schema(); $table = $schema->createTable($this->policyTableName); @@ -147,7 +147,8 @@ public function savePolicyLine($pType, array $rule) public function loadPolicy(Model $model): void { $queryBuilder = $this->connection->createQueryBuilder(); - $stmt = $queryBuilder->select('p_type', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5')->from($this->policyTableName)->execute(); + $query = $queryBuilder->select('p_type', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5')->from($this->policyTableName); + $stmt = method_exists($query, "executeQuery") ? $query->executeQuery() : $query->execute(); while ($row = $this->fetch($stmt)) { $this->loadPolicyArray($this->filterRule($row), $model);