From a050a9c222625ddab3482657ea76eb7c3e0c240e Mon Sep 17 00:00:00 2001 From: Dobando <33273950+Dobmod@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:22:19 +0800 Subject: [PATCH] BREAKING CHANGE: upgrade to PHP 8.0 and PHP-Casbin 4.0 (#75) --- .github/workflows/build.yml | 66 --------------------------- composer.json | 17 ++++--- src/EnforcerManager.php | 8 ++-- tests/DatabaseAdapterForCacheTest.php | 4 +- 4 files changed, 13 insertions(+), 82 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8dbd181..6afb60b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,73 +27,7 @@ jobs: # laravel: [ ] # stability: [ prefer-lowest, prefer-stable ] include: - # Laravel 5.5 - - php: 7.1 - laravel: 5.5.* - phpunit: ~6.0 - - php: 7.2 - laravel: 5.5.* - phpunit: ~6.0 - - php: 7.3 - laravel: 5.5.* - phpunit: ~6.0 - - # Laravel 5.6 - - php: 7.1 - laravel: 5.6.* - phpunit: ~7.0 - - php: 7.2 - laravel: 5.6.* - phpunit: ~7.0 - - php: 7.3 - laravel: 5.6.* - phpunit: ~7.0 - - # Laravel 5.7 - - php: 7.1 - laravel: 5.7.* - phpunit: ~7.5 - - php: 7.2 - laravel: 5.7.* - phpunit: ~7.5 - - php: 7.3 - laravel: 5.7.* - phpunit: ~7.5 - - # Laravel 5.8 - - php: 7.1 - laravel: 5.8.* - phpunit: ~7.5 - - php: 7.2 - laravel: 5.8.* - phpunit: ~8.0 - - php: 7.3 - laravel: 5.8.* - phpunit: ~8.0 - - # Laravel 6.x - - php: 7.2 - laravel: 6.* - phpunit: ~8.0 - - php: 7.3 - laravel: 6.* - phpunit: ~8.0 - - # Laravel 7.x - - php: 7.3 - laravel: 7.* - phpunit: ~9.0 - - php: 7.4 - laravel: 7.* - phpunit: ~9.0 - # Laravel 8.x - - php: 7.3 - laravel: 8.* - phpunit: ~9.0 - - php: 7.4 - laravel: 8.* - phpunit: ~9.0 - php: 8.0 laravel: 8.* phpunit: ~9.0 diff --git a/composer.json b/composer.json index 76b38ed..0849465 100755 --- a/composer.json +++ b/composer.json @@ -20,18 +20,17 @@ ], "license": "Apache-2.0", "require": { - "php": ">=7.1.0", - "illuminate/support": "~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", - "illuminate/database": "~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", - "illuminate/console": "~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0", - "casbin/casbin": "~3.1", - "casbin/psr3-bridge": "^1.1" + "php": ">=8.0", + "illuminate/support": "~8.0|~9.0|~10.0|~11.0", + "illuminate/database": "~8.0|~9.0|~10.0|~11.0", + "illuminate/console": "~8.0|~9.0|~10.0|~11.0", + "casbin/casbin": "~4.0" }, "require-dev": { - "phpunit/phpunit": "~7.0|~8.0|~9.0|~10.5", - "php-coveralls/php-coveralls": "^2.4", + "phpunit/phpunit": "~9.0|~10.5", + "php-coveralls/php-coveralls": "^2.7", "mockery/mockery": "^1.0", - "laravel/laravel": "~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0" + "laravel/laravel": "~9.0|~10.0|~11.0" }, "autoload": { "psr-4": { diff --git a/src/EnforcerManager.php b/src/EnforcerManager.php index 0c08164..62e3a47 100755 --- a/src/EnforcerManager.php +++ b/src/EnforcerManager.php @@ -2,10 +2,10 @@ namespace Lauthz; -use Casbin\Bridge\Logger\LoggerBridge; use Casbin\Enforcer; use Casbin\Model\Model; use Casbin\Log\Log; +use Casbin\Log\Logger\DefaultLogger; use Lauthz\Contracts\Factory; use Lauthz\Models\Rule; use Illuminate\Support\Arr; @@ -80,10 +80,10 @@ protected function resolve($name) if ($logger = Arr::get($config, 'log.logger')) { if (is_string($logger)) { - $logger = $this->app->make($logger); + $logger = new DefaultLogger($this->app->make($logger)); } - Log::setLogger(new LoggerBridge($logger)); + Log::setLogger($logger); } $model = new Model(); @@ -98,7 +98,7 @@ protected function resolve($name) ]); } - return new Enforcer($model, $adapter, Arr::get($config, 'log.enabled', false)); + return new Enforcer($model, $adapter, $logger, Arr::get($config, 'log.enabled', false)); } /** diff --git a/tests/DatabaseAdapterForCacheTest.php b/tests/DatabaseAdapterForCacheTest.php index dca8d0e..906e095 100644 --- a/tests/DatabaseAdapterForCacheTest.php +++ b/tests/DatabaseAdapterForCacheTest.php @@ -2,11 +2,9 @@ namespace Lauthz\Tests; -use Enforcer; use Lauthz\Models\Rule; use Illuminate\Foundation\Testing\DatabaseMigrations; -use Casbin\Persist\Adapters\Filter; -use Casbin\Exceptions\InvalidFilterTypeException; +use Lauthz\Facades\Enforcer; class DatabaseAdapterForCacheTest extends TestCase {