diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 7009fcb..511cff3 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -23,7 +23,7 @@ jobs:
strategy:
fail-fast: true
matrix:
- php: [ 7.1, 7.2, 7.3, 7.4 ]
+ php: [ 8.0, 8.1, 8.2, 8.3 ]
stability: [ prefer-lowest, prefer-stable ]
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
diff --git a/composer.json b/composer.json
index a551a85..1a3ae25 100755
--- a/composer.json
+++ b/composer.json
@@ -19,13 +19,14 @@
],
"license": "Apache-2.0",
"require": {
- "yiisoft/yii2": "~2.0.14",
- "casbin/casbin": "~3.1"
+ "php": ">=8.0",
+ "yiisoft/yii2": "~2.0.49",
+ "casbin/casbin": "~4.0"
},
"require-dev": {
- "phpunit/phpunit": "~7.0|~8.0|~9.0|~10.5",
+ "phpunit/phpunit": "~9.0",
"php-coveralls/php-coveralls": "^2.1",
- "yiisoft/yii2-app-basic": "~2.0.14"
+ "yiisoft/yii2-app-basic": "~2.0.49"
},
"autoload": {
"psr-4": {
diff --git a/config/permission.php b/config/permission.php
index 8cd669b..814ad0e 100644
--- a/config/permission.php
+++ b/config/permission.php
@@ -14,6 +14,14 @@
'config_text' => '',
],
+ // Yii-casbin logger.
+ 'log' => [
+ // changes whether YiiPermission will log messages to the Logger.
+ 'enabled' => false,
+ // Casbin Logger, Supported: \Psr\Log\LoggerInterface|string
+ 'logger' => 'log',
+ ],
+
// Yii-casbin adapter .
'adapter' => \yii\permission\Adapter::class,
diff --git a/phpunit.xml.dist b/phpunit.xml
old mode 100755
new mode 100644
similarity index 80%
rename from phpunit.xml.dist
rename to phpunit.xml
index 17afffb..2dc7386
--- a/phpunit.xml.dist
+++ b/phpunit.xml
@@ -1,28 +1,28 @@
-
-
-
-
- ./tests/
-
-
-
-
- ./src
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ ./tests/
+
+
+
+
+ ./src
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Permission.php b/src/Permission.php
index 5485393..ca74181 100644
--- a/src/Permission.php
+++ b/src/Permission.php
@@ -5,6 +5,8 @@
use yii\base\Component;
use Casbin\Model\Model;
use Casbin\Enforcer;
+use Casbin\Log\Log;
+use Casbin\Log\Logger\DefaultLogger;
use yii\permission\models\CasbinRule;
use Yii;
@@ -23,6 +25,8 @@ class Permission extends Component
public $config = [];
+ public $logger = null;
+
public function __construct($config = [])
{
$this->config = $this->mergeConfig(
@@ -38,6 +42,16 @@ public function __construct($config = [])
} elseif ('text' == $this->config['model']['config_type']) {
$this->model->loadModelFromText($this->config['model']['config_text']);
}
+
+ if ($logger = $this->config['log']['logger']) {
+ if ($logger === 'log') {
+ $this->logger = new DefaultLogger();
+ } else {
+ $this->logger = new DefaultLogger(Yii::$container->get($logger));
+ }
+
+ Log::setLogger($this->logger);
+ }
}
/**
@@ -68,7 +82,7 @@ public function enforcer($newInstance = false)
{
if ($newInstance || is_null($this->enforcer)) {
$this->init();
- $this->enforcer = new Enforcer($this->model, $this->adapter);
+ $this->enforcer = new Enforcer($this->model, $this->adapter, $this->logger, !is_null($this->logger));
}
return $this->enforcer;