From 377ee237cfe9f2b95497b3e6f8c36bcf64d25493 Mon Sep 17 00:00:00 2001 From: Dobando <33273950+Dobmod@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:52:30 +0800 Subject: [PATCH] BREAKING CHANGE: upgrade to PHP 8.0 and PHP-Casbin 4.0 (#48) --- .github/workflows/default.yml | 2 +- .travis.yml | 30 ------------------------------ composer.json | 14 +++++++------- src/TauthzService.php | 21 ++++++++++----------- 4 files changed, 18 insertions(+), 49 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 429923b..e036d24 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: true matrix: - php: [ 7.2, 7.3, 7.4, 8.0, 8.1, 8.2 ] + php: [ 8.0, 8.1, 8.2, 8.3 ] name: PHP${{ matrix.php }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a59119f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: php - -sudo: false - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -services: - - mysql - -before_install: - - travis_retry composer self-update - - mysql -e 'create database if not exists tauthz;' - -install: - - travis_retry composer install --prefer-dist --dev --no-suggest --no-interaction - -before_script: - - export XDEBUG_MODE=coverage - -script: - - vendor/bin/phpunit --version - - mkdir -p build/logs - - vendor/bin/phpunit - -after_script: - - travis_retry vendor/bin/php-coveralls -v diff --git a/composer.json b/composer.json index 40f3767..9d537ee 100644 --- a/composer.json +++ b/composer.json @@ -20,15 +20,15 @@ ], "license": "Apache-2.0", "require": { - "casbin/casbin": "~3.0", - "topthink/framework": "~6.0|^8.0.3", - "topthink/think-migration": "^3.1.0", - "casbin/psr3-bridge": "^1.1" + "php": ">=8.0", + "casbin/casbin": "~4.0", + "topthink/framework": "^8.0.3", + "topthink/think-migration": "^3.1.0" }, "require-dev": { - "phpunit/phpunit": "~7.0|~8.0|~9.0", - "php-coveralls/php-coveralls": "^2.4", - "topthink/think": "~6.0|~8.0" + "phpunit/phpunit": "~9.0", + "php-coveralls/php-coveralls": "^2.7", + "topthink/think": "~8.0" }, "autoload": { "psr-4": { diff --git a/src/TauthzService.php b/src/TauthzService.php index e0f6061..e0dee93 100644 --- a/src/TauthzService.php +++ b/src/TauthzService.php @@ -2,10 +2,10 @@ namespace tauthz; -use Casbin\Bridge\Logger\LoggerBridge; use Casbin\Enforcer; use Casbin\Model\Model; use Casbin\Log\Log; +use Casbin\Log\Logger\DefaultLogger; use think\Service; use tauthz\command\Publish; @@ -42,7 +42,15 @@ public function register() $model->loadModel($config['model']['config_text']); } - return new Enforcer($model, app($adapter), $this->app->config->get('tauthz.log.enabled', false)); + if ($logger = $this->app->config->get('tauthz.log.logger')) { + if (is_string($logger)) { + $logger = new DefaultLogger($this->app->make($logger)); + } + + Log::setLogger($logger); + } + + return new Enforcer($model, app($adapter), $logger, $this->app->config->get('tauthz.log.enabled', false)); }); } @@ -55,15 +63,6 @@ public function boot() { $this->mergeConfigFrom(__DIR__.'/../config/tauthz.php', 'tauthz'); - // 设置 Casbin Logger - if ($logger = $this->app->config->get('tauthz.log.logger')) { - if (is_string($logger)) { - $logger = $this->app->make($logger); - } - - Log::setLogger(new LoggerBridge($logger)); - } - $this->commands(['tauthz:publish' => Publish::class]); }